c# check if a directory is hidden?

user436238 picture user436238 · Aug 31, 2010 · Viewed 8k times · Source

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?

Answer

Garis M Suero picture Garis M Suero · Aug 31, 2010

Try this:

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