* FASTEST directory listing *

I have massive directories and I would like to read all the files as quickly as possible. I mean, not DirectoryInfo.GetFiles is fast but "get-clusters-from-disk-low-level" fast.

Of course, .NET 2.0, C #

A similar question was here, but this approach was not good:

C # directory directory with bulk directory

Someone suggested pInvoke on FindFirst / FindNext. Has anyone tried this and were able to share the results?

+6
c # directory file-io
source share
3 answers

For a β€œnormal” approach, it basically comes down to FindFirstFile / FindNextFile , you really don't get much faster than that ... and it's not super-turbo-fast.

If you really need speed, look through the MFT manually, but be aware that this requires administrator privileges and is prone to interruption when updating NTFS (and, oh, yes, it will not work for file systems other than NTFS). Maybe you should take a look at this code , which has USN and MFT.

However, there may be another solution. If your application is running continuously and you need to pick up the changes, you can start with a single slow pass FindFirstFile / FindNextFile , and then use the directory change notification support to get update information ... that works for limited users, and is independent of file system structures.

+5
source share

For best performance, you can run the P / Invoke NtQueryDirectoryFile, documented as ZwQueryDirectoryFile.

(This is not enough to directly access the disk and directly read the structures of the raw file systems, which is usually impractical.)

+3
source share

Try using something like this DirectoryManager and refine it to your needs. Faster than the .NET Framework GetDirectories() or GetFiles() because we skipped cross-platform validations and adaptations.

+1
source share

All Articles