【发布时间】:2012-05-16 00:35:55
【问题描述】:
我需要获取所有 Word 文档的列表。 *.doc 和 *.docx 存储在基于 Windows 的文件夹中,包含许多子文件夹和子子文件夹等...
Searching for a file with C# 有一个有效的答案,它已有 2 年历史,搜索 1500 个文件需要 10 秒,(将来可能会有 10,000 个或更多)。我将发布我的代码,该代码基本上是上述链接的副本。谁有更好的解决方案?
DateTime dt = DateTime.Now;
DirectoryInfo dir = new DirectoryInfo(MainFolder);
List<FileInfo> matches =
new List<FileInfo>(dir.GetFiles("*.doc*",SearchOption.AllDirectories));
TimeSpan ts = DateTime.Now-dt;
MessageBox.Show(matches.Count + " matches in " + ts.TotalSeconds + " seconds");
【问题讨论】:
-
而不是 List 写入字典。它很快。否则我认为你的速度最快。
-
@RobertLevy:他自己给出了那个链接。
-
@RobertLevy wow 在评论之前阅读问题,我在我的问题中引用了该确切链接
-
也许这个链接会对你有所帮助:stackoverflow.com/questions/7865159/…