我需要获取所有 Word 文档的列表。*.doc 和 *.docx 存储在基于 Windows 的文件夹中,包含许多子文件夹和子子文件夹等...
用 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");