简体   繁体   English

如何以IEnumerable而不是数组的形式获取文件/文件夹列表

[英]how to get a list of files / folders as an IEnumerable and not an array

how to get a list of files / folders as an IEnumerable and not an array? 如何以IEnumerable而不是数组的形式获取文件/文件夹列表?

the reason I want to do this is a have many folders with 20,000+ files in them, and i need to loop through all of them but do not want to wait for them to be compiled into an array. 我要执行此操作的原因是其中有许多文件夹,其中包含20,000+个文件,我需要遍历所有文件夹,但不想等待它们被编译为数组。 but just want to go through one at a time. 但只想一次经历一个。

also i'm using .net 3.5 not v4 我也使用.net 3.5 not v4

It's too bad you're not on .net 4 - looks like they added this functionality . 不幸的是,您不在.net 4上-好像他们添加了此功能

Aside from that, I can't provide any code as I have no experience doing this, but maybe P/Invoke wrapping some C code using FindFirstFile/FindNextFile ? 除此之外,我无法提供任何代码,因为我没有这样做的经验,但是也许P / Invoke使用FindFirstFile / FindNextFile包装了一些C代码?

EDIT: A little googling turned up some code on Code Project . 编辑:有点谷歌搜索出现在代码项目上的一些代码

I'm pretty sure Mono has an API for this, and you can include the mono dll's in your .Net 3.5 application. 我很确定Mono具有与此相关的API,并且您可以在.Net 3.5应用程序中包含mono dll。 I'll try and dig up the exacy library and syntax. 我将尝试挖掘exacy库和语法。

Your other option is to use Reflector and try to back port the new .Net 4 functionality. 您的另一个选择是使用Reflector并尝试向后移植新的.Net 4功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM