Number of files inside a directory (including all subdirectories)

  • Thread starter Thread starter jj
  • Start date Start date
J

jj

Hi folks:

I can get the list of files in a certain directory by using
Directory.GetFiles("c:\temp").
But I want to get the number of files (ex. 20) within a directory including
all subdirectories. I don't want to scan through the whole recursively and
count. Is there a way?

Thanks
John
 
John,

You should be able to make a call to FindFirstFileEx, FindNextFile, etc,
etc through the P/Invoke layer. Just set the filter to "*" and you should
be able to get a complete count.

You might also be able to do a select from the WMI provider for the
windows file system, but this could really hit you performance wise.

Hope this helps.
 
Back
Top