最有效的方式使用C#找到磁盘上的所有exe文件? [英] Most efficient way to find all exe files on disk using C#?
问题描述
什么是用C#找到磁盘上的所有exe文件的最有效的方法是什么?
有将在程序的后台线程完成所以磁盘使用率应该尽可能地小。
It will be done in background thread in program so disk usage should be as small as possible.
推荐答案
您所提供的链接是在C#(与.NET 4.0)最有效的方法:
Directory.EnumerateFiles方法
The link you provided is the most efficient way in C# (with .Net 4.0): Directory.EnumerateFiles Method
的.NET之前版本必须使用造成大硬盘内存问题一个较慢的方法,@hatchet表现出一个很好的例子:<一href=\"http://stackoverflow.com/questions/724148/is-there-a-faster-way-to-scan-through-a-directory-recursively-in-net\">Is有通过目录递归.NET?
Prior versions of .Net had to use a slower method that caused memory issues on large drives, @hatchet showed a great example: Is there a faster way to scan through a directory recursively in .NET?
作为乔恩斯基特提到这里,我不会建议使用TPL:
<一href=\"http://stackoverflow.com/questions/4149873/task-parallel-library-for-directory-traversal#comment14095131_4149873\">Task对于目录遍历并行库
I wouldn't suggest using the TPL as Jon Skeet mentions here: Task Parallel Library for directory traversal
如果你看到这个 MSDN链接第一个注释:迭代文件目录与平行的类我不甚至觉得微软曾与该TPL方法无论成功。
If you see the first comment in this MSDN link: Iterate File Directories with the Parallel Class I dont even think Microsoft had success with this TPL method either.
其他的建议,我已经使用LOGPARSER的,您可以用C#中使用它!它是一个免费的微软产品,但我不知道如何重新DIST权限,我不得不把它列入我的包分开我最后一次使用它。它充分的蝇类,比飞驰的列车还快!
The other suggestion I have is using LogParser and you can use it with C#! Its a free Microsoft product but I'm not sure about re-dist permissions, I had to include it in my package separately last time I used it. It full on flys, faster than a speeding train!
按@spender评论我发现了一个日志分析器例如的日期查找文件180天以上,你可以尝试一下,如果它有用适应它:
As per @spender comment I found a Log Parser example that finds files dated 180 days and older, you could try it out and adapt it if its useful:
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
%源%可能是类似于C:\\ *。exe文件如图所示的参数C:\\ TEMP \\ *。*。保存上面cc.sql,使用以下语法运行它:
%source% could be something like c:\*.exe as shown in the argument c:\temp\*.*. Save the above as cc.sql, run it with the following syntax:
C:\Temp\Tools\Logparser>LogParser.exe file:cc.sql?source="c:\temp\*.*"+day="180" -i:FS -preserveLastAccTime -rtp:-1
修改
感谢upvotes家伙!我在2005年(.NET 2.0发布前),因为日志分析器建议是如此受欢迎,使这个事件分析器应用我想我会分享您可以在.NET中使用LOGPARSER的方式
Thanks for the upvotes guys! I made this Event Analyser app in 2005 (before .net 2.0 was released) and since the Log Parser suggestion was so popular I thought I'd share the way you can use LogParser in .Net
好乡亲在 HTTP://visuallogparser.$c$cplex.com/ 有
与源$ C $ C提供给我们。
The good folks over at http://visuallogparser.codeplex.com/ have provided us with the source code.
打开 VisualLogParser 在VS2010的解决方案,忽略有关调试的提示,该解决方案加载后, F5,在此查询和preSS去设置组合框以FS(文件系统),粘贴。
Open the VisualLogParser solution in VS2010, ignore the prompt about debugging, after the solution loads, F5, set the combo-box to FS (FileSystem), paste in this query and press 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应用程序,搜索目录,并比较结果!!! 的
这篇关于最有效的方式使用C#找到磁盘上的所有exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!