I need my program to count the number of files on a disk drive.
What is the fastest way to do so?
Directory.GetFiles() is not an alternative, as it is very slow.
I need my program to count the number of files on a disk drive.
What is the fastest way to do so?
Directory.GetFiles() is not an alternative, as it is very slow.
Did you try import kernel32.dll
and use it?
There is a good implementation example someone posted before here : https://stackoverflow.com/a/724184/912851. It might be worthwhile looking at.
Edit: The fastest one I saw in my life is this application. It uses ntfs journals. and within seconds it lists millions of files on my harddisk. I think they have a sdk and sources on C++ or c. Maybe you can create a managed dll and use on c#?
you could read out the drive USN journal, this is very fast but you need administrator rights
Func<string, int> files = null;
files = p => Directory.GetFiles(p).Length() + Directory.GetDirectories(p).Select(p1 => files(p1));
int count = files(@"c:\");
Horrible but linqy!