C# 在目录中搜索大量文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Searching directories for tons of files?
提问by Adam V
I'm using MSVE, and I have my own tiles I'm displaying in layers on top. Problem is, there's a ton of them, and they're on a network server. In certain directories, there are something on the order of 30,000+ files. Initially I called Directory.GetFiles, but once I started testing in a pseudo-real environment, it timed out.
我正在使用 MSVE,并且我有自己的图块,我在顶部的图层中显示。问题是,它们有很多,而且它们都在网络服务器上。在某些目录中,大约有 30,000 多个文件。最初我调用 Directory.GetFiles,但是一旦我开始在伪真实环境中进行测试,它就会超时。
What's the best way to programatically list, and iterate through, this many files?
以编程方式列出和迭代这么多文件的最佳方法是什么?
Edit: My coworker suggested using the MS indexing service. Has anyone tried this approach, and (how) has it worked?
编辑:我的同事建议使用 MS 索引服务。有没有人尝试过这种方法,并且(如何)有效?
采纳答案by Ronnie
I've worked on a SAN system in the past with telephony audio recordings which had issues with numbers of files in a single folder - that system became unusable somewhere near 5,000 (on Windows 2000 Advanced Server with an application in C#.Net 1.1)- the only sensible solution that we came up with was to change the folder structure so that there were a more reasonable number of files. Interestingly Explorer would also time out!
我过去曾在 SAN 系统上使用电话录音,该系统在单个文件夹中的文件数量存在问题 - 该系统在接近 5,000 的某个地方变得无法使用(在 Windows 2000 Advanced Server 上使用 C#.Net 1.1 中的应用程序)-我们想出的唯一明智的解决方案是更改文件夹结构,以便有更合理的文件数量。有趣的是,资源管理器也会超时!
The convention we came up with was a structure that broke the structure up in years, months and days - but that will depend upon your system and whether you can control the directory structure...
我们提出的约定是一种以年、月和日为单位分解结构的结构 - 但这将取决于您的系统以及您是否可以控制目录结构......
回答by Stu
None. .NET relies on underlying Windows API calls that really, really hate that amount of files themselves.
没有任何。.NET 依赖于底层的 Windows API 调用,而这些调用本身就非常非常讨厌这种数量的文件。
As Ronnie says: split them up.
正如罗尼所说:把他们分开。
回答by GateKiller
You could use DOS?
你能用DOS吗?
DIR /s/b > Files.txt
回答by Greg Hurlman
Definitely split them up. That said, stay as far away from the Indexing Service as you can.
肯定把他们分开了。也就是说,尽可能远离索引服务。
回答by lomaxx
You could also look at either indexing the files yourself, or getting a third part app like google desktop or copernicto do it and then interface with their index. I know copernic has an API that you can use to search for any file in their index and it also supports mapping network drives.
您还可以查看自己为文件编制索引,或者使用第三方应用程序(如 google desktop 或copernic)来执行此操作,然后与他们的索引进行交互。我知道 copernic 有一个 API,你可以用它来搜索索引中的任何文件,它还支持映射网络驱动器。