EnumerateFiles()在.NET 3.5当量 [英] EnumerateFiles() equivalent in .NET 3.5

查看:173
本文介绍了EnumerateFiles()在.NET 3.5当量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图清理过的文件150K使用.NET 3.5和PowerShell目录中。既然有这么多的文件,我不想读的一切在一次影响服务器的性能。是否与.NET 3.5或PowerShell中或通过PInvoke的访问方法的任何机制,让我懒洋洋地加载的文件吗?谢谢您的帮助。

I am trying to clean up over 150K of files within a directory using .NET 3.5 and PowerShell. Since there are so many files I do not want to impact the server performance by reading everything in at once. Is there any mechanism with .NET 3.5 or PowerShell or methods accessible via PInvoke that would allow me to lazily load the files? Thank you for your assistance.

推荐答案

如果按加载你的意思是让在一个慵懒的方式目录中的文件列表,你有两个选择。

由于.NET 4.0,您可以使用新的 Directory.EnumerateFiles 的API来获得在特定目录中的文件流(懒惰)序列。搜索返回的项目上的需求,所以并不需要尽可能多的内存与现有的GetFiles方法。

As of .NET 4.0, you can use the new Directory.EnumerateFiles APIs to get a streaming (lazy) sequence of files in a particular directory. The search returns items on-demand, and so doesn't require as much memory as the existing GetFiles methods.

如果您不能使用.NET 4中,那么你将不得不推出自己的流媒体文件枚举。这需要使用 用FindFirstFile和<一HREF =htt​​p://msdn.microsoft.com/en-us/library/aa364428%28v=VS.85%29.aspx相对=nofollow> FindNextFile 的Win32 API。不过,你可以看看在$ C $此实现的CProject,因为它似乎是这一点。

If you cannot use .NET 4, then you will have to roll your own streaming file enumerator. This would require using the FindFirstFile and FindNextFile Win32 APIs. However, you could take a look at this implementation on CodeProject, as it appears to be just that.

这篇关于EnumerateFiles()在.NET 3.5当量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆