My application indexes contents of all hard drives on end users computers. I am using Directory.GetFiles and Directory.GetDirectories to recursively process the whole folder structure. I am indexing only a few selected file types (up to 10 filetypes).
I am seeing in profiler that most of the indexing time is spent in enumerating files and folders - depending on ratio of files that will actually be indexed up to 90 percent of time.
I would like to make the indexing as fast as possible. I have already optimized the indexing itself and processing of the indexed files.
I was thinking using Win32 API calls, but I am actually seeing in the profiler that most of the processing time is actually spent on these API calls done by .NET.
Is there a (possibly low level) method accessible from C# that would make enumeration of files/folders at least partially faster?
As requested in the comment, my current code (just a scheme with irrelevant parts trimmed):
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;
}
}
}