*最快*目录列表 [英] *FASTEST* directory listing
问题描述
我拥有庞大的目录,我想和我一样快可以读取所有文件。我的意思是,没有DirectoryInfo.GetFiles快,但得到集群 - 从磁盘低级别的'快。
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.
当然,.NET 2.0,C#
Of course, .NET 2.0, c#
类似的问题在这里,但这种做法是没有任何好处的:
Similar question was here, but this approach wasn't any good:
的http://stackoverflow.com/questions/1941223/c-directory-listing-massive-directory
有人建议在使用FindFirst / FindNext中的PInvoke。任何人都试过了,并能够分享成果?
Someone suggested pInvoke on FindFirst/FindNext. Anybody tried that and is able to share results?
推荐答案
有关一个正常的方式,基本上都可以归结为用FindFirstFile
/ FindNextFile
,你不是真的比这快多了...这是不是超级涡轮快
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.
如果您真的需要的速度,考虑阅读的 MFT 手动 - 但要知道,这需要管理员权限,而且很容易打破NTFS时被更新(和,噢,不会对非NTFS文件系统的工作)。你可能想看看拥有的 ://en.wikipedia.org/wiki/USN_Journal> USN 和MFT的东西。
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.
不过,也许有不同的解决方案。如果您的应用不断磨合和需求回暖的变化,您可以通过启动王兰坤慢用FindFirstFile
/ FindNextFile
传球,然后使用目录更改通知支持被告知的更新......这对有限的用户有效,并且不依赖于文件系统的结构。
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.
这篇关于*最快*目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!