您提供的链接是 C# 中最有效的方法(使用 .Net 4.0):Directory.EnumerateFiles 方法 http://msdn.microsoft.com/en-us/library/dd383458
.Net 的早期版本必须使用较慢的方法,这会导致大型驱动器出现内存问题,@hatchet 展示了一个很好的例子:是否有更快的方法在 .NET 中递归地扫描目录? https://stackoverflow.com/questions/724148/is-there-a-faster-way-to-scan-through-a-directory-recursively-in-net
我不建议使用 TPL,正如 Jon Skeet 在这里提到的那样:用于目录遍历的任务并行库 https://stackoverflow.com/questions/4149873/task-parallel-library-for-directory-traversal#comment14095131_4149873
如果你看到这里的第一条评论MSDN 链接:使用并行类迭代文件目录 http://msdn.microsoft.com/en-us/library/ff477033.aspx我什至认为微软在这种 TPL 方法上也没有取得成功。
我的另一个建议是使用 LogParser,您可以将它与 C# 一起使用!它是一个免费的微软产品,但我不确定重新分配权限,我上次使用它时必须将它单独包含在我的包中。它满是苍蝇,比疾驰的火车还要快!
根据 @spender 评论,我发现了一个日志解析器示例 http://forums.iis.net/t/1183252.aspx找到 180 天及以上的文件,您可以尝试一下,如果有用的话进行调整:
SELECT
ContentPath, [Days (Old)], FileName, [Creation Date Time]
USING creationtime AS [Creation Date Time],
TO_DATE([Creation Date Time]) AS Cdate,
SUB(TO_LOCALTIME(SYSTEM_TIMESTAMP()), Cdate) AS Days,
DIV(TO_INT(Days),86400) As [Days (Old)],
EXTRACT_PATH(TO_LOWERCASE(path)) AS ContentPath,
TO_LOWERCASE(name) AS FileName
FROM %source%
WHERE
(attributes NOT LIKE 'D%')
AND
([Days (Old)] >= TO_INT('%day%'))
ORDER BY [Creation Date Time] DESC
%source% 可能类似于 c:\*.exe,如参数 c:\temp\*.* 中所示。将以上内容保存为 cc.sql,使用以下语法运行它:
C:\Temp\Tools\Logparser>LogParser.exe file:cc.sql?source="c:\temp\*.*"+day="180" -i:FS -preserveLastAccTime -rtp:-1
EDIT
谢谢小伙伴们的点赞!我做的事件分析器 http://EventAnalyser.AppointmentsBook.com应用程序于 2005 年(在 .net 2.0 发布之前),由于 Log Parser 建议非常受欢迎,我想我应该分享一下在 .Net 中使用 LogParser 的方式
好人在http://visuallogparser.codeplex.com/ http://visuallogparser.codeplex.com/有
为我们提供了源代码。
打开可视化日志解析器 http://visuallogparser.codeplex.com/VS2010 中的解决方案,忽略有关调试的提示,解决方案加载后,F5,将组合框设置为 FS(文件系统),粘贴此查询并按 go。
SELECT
ContentPath, [Days (Old)], FileName, [Creation Date Time]
USING creationtime AS [Creation Date Time],
TO_DATE([Creation Date Time]) AS Cdate,
SUB(TO_LOCALTIME(SYSTEM_TIMESTAMP()), Cdate) AS Days,
DIV(TO_INT(Days),86400) As [Days (Old)],
EXTRACT_PATH(TO_LOWERCASE(path)) AS ContentPath,
TO_LOWERCASE(name) AS FileName
FROM 'c:\*.exe'
WHERE
(attributes NOT LIKE 'D%')
AND
([Days (Old)] >= TO_INT('180'))
ORDER BY [Creation Date Time] DESC
同时,您可能希望运行任何其他 .Net 应用程序来搜索目录并比较结果!