c# check if a directory is hidden? [duplicate]
Asked Answered
F

1

7

Possible Duplicate:
How to test if directory is hidden in C#?

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) == (FileAttributes.Hidden)) 
{ 
     //do stuff
}

With this if statement i would like to test if the directory is hidden. Although the directory really is hidden, my program doesn't get into the do stuff because only the directory flag of the attributes is set. Any suggestions?

Frig answered 31/8, 2010 at 18:27 Comment(4)
Check that the directory is actually hidden, that code worked for me. Also, you don't need parentheses around FileAttributes.Hidden.Atencio
You are going to have to figure out how this directory managed to hide itself without the attribute.Seismism
apparently the check works if for c:\test for example but it doesn't for a folder on my desktopFrig
Okay, sorry to bother you guys. Problem mysteriously solved. Thanks for the help.Frig
D
8

Try this:

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) != 0)
{
   //do stuff
}
Danelledanete answered 31/8, 2010 at 18:34 Comment(1)
if (dir.Attributes.HasFlag(FileAttributes.Hidden)) betterRespirator

© 2022 - 2024 — McMap. All rights reserved.