Number of files inside a directory (including all subdirectories)

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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