views:

84

answers:

2

how to get a list of files / folders as an IEnumerable and not an array?

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. but just want to go through one at a time.

also i'm using .net 3.5 not v4

+5  A: 

It's too bad you're not on .net 4 - looks like they added this functionality.

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?

EDIT: A little googling turned up some code on Code Project.

Chris Shaffer
Looking with Reflector at the new .NET 4 methods, it seems these are actually implemented with FindFirstFile/FindNextFile.
dtb
+1  A: 

I'm pretty sure Mono has an API for this, and you can include the mono dll's in your .Net 3.5 application. I'll try and dig up the exacy library and syntax.

Your other option is to use Reflector and try to back port the new .Net 4 functionality.

Mikael Svenson