My applications index the contents of all hard drives on end-user computers. I use Directory.GetFiles and Directory.GetDirectories to recursively process the entire folder structure. I index only a few selected file types (up to 10 file types).
I see in the profiler that most of the indexing time is spent on listing files and folders - depending on the ratio of files that will actually be indexed up to 90% of the time.
I would like to do indexing as quickly as possible. I have already optimized the indexing and processing of indexed files themselves.
I thought using Win32 API calls, but I really see in the profiler that most of the processing time is actually spent on these API calls made by .NET.
Is there a way (possibly low level) available from C # that will make listing files / folders at least partially faster?
As stated in the comment, my current code (only the circuit with inappropriate details is cut off):
private IEnumerable<IndexedEntity> RecurseFolder(string indexedFolder) { //for a single extension: string[] files = Directory.GetFiles(indexedFolder, extensionFilter); foreach (string file in files) { yield return ProcessFile(file); } foreach (string directory in Directory.GetDirectories(indexedFolder)) { //recursively process all subdirectories foreach (var ie in RecurseFolder(directory)) { yield return ie; } } }
Marek source share