Elmex
Elmex

Reputation: 3361

Performance problems counting the files with System.IO.Directory.GetFiles()

I use in a C# program

System.IO.Directory.GetFiles(dirname, "*.*", System.IO.SearchOption.AllDirectories).Length;

to count to number of files in a directory(and its subdirectories) on a share. I do this for many directories within a loop. The problem is now, that after 20-30 calls of GetFiles(...).Length my program is suddenly frozen or becomes very slow. What could be the reason for that and how can this problem be solved! Are there workarounds?

Upvotes: 9

Views: 3962

Answers (2)

Grozz
Grozz

Reputation: 8425

Are you sure you aren't somehow storing the results of previous calls making your application starve on memory? Check the memory allocation for your application in processes tab of Task Manager.

Upvotes: 0

Kottan
Kottan

Reputation: 5056

Take a look at http://www.codeproject.com/KB/files/FastDirectoryEnumerator.aspx. Mybe this article will help you.

Upvotes: 7

Related Questions