* FASTEST *目录列表 [英] *FASTEST* directory listing
问题描述
我有大量的目录,我想尽快阅读所有的文件。我的意思是,不是DirectoryInfo.GetFiles快速,但'快速从磁盘低级别获取集群。
当然,.NET 2.0,c# p>
类似的问题在这里,但这种做法并不好:
有人建议pInvoke on FindFirst /找下一个。任何人都尝试过并且能够共享结果?
对于正常的方法,基本上都可以归结为 FindFirstFile
/ FindNextFile
,你没有真的比这更快得多...那不是超级涡轮增压
如果您真的需要速度,请查看阅读 MFT - 但是要知道这需要管理员权限,并且在NTFS更新时容易出现中断(而且,对于非NTFS文件系统,这可能不起作用)。您可能需要查看此代码,其中<一个href =http://en.wikipedia.org/wiki/USN_Journal =noreferrer> USN 和MFT的东西。
然而,也许有一个不同的解决方案。如果您的应用程序不断运行并需要接收更改,则可以通过执行一个缓慢的开始[code] FindFirstFile / FindNextFile
通过,然后使用目录更改通知支持被通知更新...适用于有限的用户,并且不依赖于文件系统结构。
I have massive directories, and I would like to read all the files as fast as I can. I mean, not DirectoryInfo.GetFiles fast, but 'get-clusters-from-disk-low-level' fast.
Of course, .NET 2.0, c#
Similar question was here, but this approach wasn't any good:
C# Directory listing massive directory
Someone suggested pInvoke on FindFirst/FindNext. Anybody tried that and is able to share results?
For a "normal" approach, basically everything boils down to FindFirstFile
/FindNextFile
, you don't really get much faster than that... and that isn't super-turbo-fast.
If you really need speed, look into reading the MFT manually - but know that this requires admin privileges, and is prone to break whenever NTFS gets updated (and, oh yeah, won't work for non-NTFS filesystems). You might want to have a look at this code which has USN and MFT stuff.
However, perhaps there's a different solution. If your app is running constantly and needs to pick up changes, you can start off by doing one slow FindFirstFile
/FindNextFile
pass, and then use directory change notification support to be informed of updates... that works for limited users, and doesn't depend on filesystem structures.
这篇关于* FASTEST *目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!