Identify hidden folders

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I loop through all the folders in a directory.
I want to be able to check if a folder is set as hidden.

I've been playing around with FileAttributes, see below. But its not working.
FileAttributes fileAttributes = File.GetAttributes(fileName);
It returns a value of 34 which is not one of the values in the
FileAttributes Enumeration.

Anyone done this before? How can i test if its hidden or not?

thank you
 
I loop through all the folders in a directory.
I want to be able to check if a folder is set as hidden.

I've been playing around with FileAttributes, see below. But its not
working.
FileAttributes fileAttributes = File.GetAttributes(fileName);
It returns a value of 34 which is not one of the values in the
FileAttributes Enumeration.

Anyone done this before? How can i test if its hidden or not?
[PD] What you get from GetAttributes is a bit mask of attributes. I.e. if
you are asking for a hidden directory you should get
18=FileAttributes.Directory(=16)|FileAttributes.Hidden(=2). I tested it on
a hidden directory on my computer and it works fine.
 
I'm getting 34.
which doesnt appear in the list of members for FileAttributes Enumeration.

Any ideas???

thanks
 
By the way, the way to test the Hidden attribute in the return value is
like this:

FileAttributes attr = File.GetAttributes(fileName);
if ((attr & FileAttributes.Hidden) != 0)
{
... do something for hidden file ...
}

Note that there is only a single "&", the bitwise "and" operator, not a
double &&.
 
CodeRazor,

Beside what the other said I just want to remaind that files with System
attribute also appear hiddent.
 
Hi,

Of course it does not, it's a combination of several values, it's called a
mask field ,
Let's say that you have this enum:

firstElement = 1 ; // 00000001 in binary
secondElement=2; // 00000010
ThirdElement=4; // 00000100

if you have 3 it means that both firstElement and secondElement are active.

take a look at http://en.wikipedia.org/wiki/Bit_mask
 
Back
Top