Count the number of hidden files and directories

G

Guest

Is there a way to determine the number of hidden files/directories within a
directory? This is what I’m doing now:

System.IO.DirectoryInfo rootPath;
System.IO.FileSystemInfo[] dirs, files;
int numOfDirs = 0, numOfFiles = 0;

di = new System.IO.DirectoryInfo(“blahâ€);
dirs = rootPath.GetDirectories();
files = rootPath.GetFiles();

for (int i=0; i<dirs.Length; i++)
numOfDirs += ((dirs.Attributes & System.IO.FileAttributes.Hidden) ==
System.IO.FileAttributes.Hidden) ? 0 : 1;

for (int i=0; i<files.Length; i++)
numOfFiles += ((files.Attributes & System.IO.FileAttributes.Hidden) ==
System.IO.FileAttributes.Hidden) ? 0 : 1;

It seems like there must be a better way?
This can’t be very efficient.

Thanks,

Dale
 
S

Steven Cheng[MSFT]

Hi Dale,

Regarding on the problem you mentioned ,I'm finding proper resource to
assist you and will reply as soon as possible. Thanks for your
understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi Dale,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the count for hidden
files and directorys under certain directory. If there is any
misunderstanding, please feel free to let me know.

As far as I know, there isn't a method in current .NET framework for us to
get the count directly. In my opinion, the code you have provided is quite
good. I will do this also in this case.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

You understand perfectly. It looks like I am already using the best method
available.

Thanks for your time.

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top