Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.IO;
namespace IOExtensions
{
public static class DirectoryExtensions
{
public static bool IsHidden(this DirectoryInfo dir)
{
return (dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
}
public static bool IsReadonly(this DirectoryInfo dir)
{
return (dir.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
}
public static DirectoryInfo SetHidden(this DirectoryInfo dir, bool hidden)
{
if (hidden)
{
dir.Attributes |= FileAttributes.Hidden;
}
else
{
dir.Attributes &= ~FileAttributes.Hidden;
}
return dir;
}
public static DirectoryInfo SetReadonly(this DirectoryInfo dir, bool @readonly)
{
if (@readonly)
{
dir.Attributes |= FileAttributes.ReadOnly;
}
else
{
dir.Attributes &= ~FileAttributes.ReadOnly;
}
return dir;
}
}
}
using System.IO;
namespace IOExtensions
{
public static class FileExtensions
{
public static bool IsHidden(this FileInfo file)
{
return (file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
}
public static bool IsReadonly(this FileInfo file)
{
return (file.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
}
public static FileInfo SetHidden(this FileInfo file, bool hidden)
{
if (hidden)
{
file.Attributes |= FileAttributes.Hidden;
}
else
{
file.Attributes &= ~FileAttributes.Hidden;
}
return file;
}
public static FileInfo SetReadonly(this FileInfo file, bool @readonly)
{
if (@readonly)
{
file.Attributes |= FileAttributes.ReadOnly;
}
else
{
file.Attributes &= ~FileAttributes.ReadOnly;
}
return file;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.