Reputation: 2111
I made a hidden directory in drive F and named it "File".
This code shows it is hidden file : Console.WriteLine(dc.Attributes);
But when I use DirectoryInfo Attributes to check if it's a hidden file it won't work.
Here is the code :
DirectoryInfo dc = new DirectoryInfo(@"F:\File");
Console.WriteLine(dc.Attributes);
if (dc.Attributes == FileAttributes.Hidden)
{
Console.WriteLine("HIDDEN");
}
else
{
Console.WriteLine("NOT HIDDEN");
}
It writes NOT HIDDEN
. What should I do with that?
Thanks in advance
Upvotes: 0
Views: 250
Reputation: 1242
If you're using .NET 4 and above do :
dir.Attributes.HasFlag(FileAttributes.Hidden)
Upvotes: 2
Reputation: 35338
The problem is that the attributes value is a bitwise combination of multiple attributes.
To test whether the FileAttributes.Hidden
attribute is set, you need to do this:
if ((dc.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
I would suggest you read about how bitwise combinations work.
Upvotes: 2