Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 267
Elmex Avatar asked Jul 19 '11 12:07

Elmex


1 Answers

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

like image 187
Kottan Avatar answered Oct 24 '22 18:10

Kottan