Retreiving file list from a directory

  • Thread starter Thread starter ThisBytes5
  • Start date Start date
T

ThisBytes5

Is there a built in way in .net to retrieve all the files in a
directory one at a time? I have to process a bunch of files serially
and there can be more than 100K files in the dir. I am trying to avoid
FileInfo[] or System.IO.Directory.GetCurrentDirectory() as I don't
want all the info loaded into memory at once.

Previously I would just use FindFirst and Findnext

Thanks
Wayne
 
Wayne,

In this case, you would want to call FindFirstFileEx through the
P/Invoke layer. It will return a handle which represents the search. Then,
you would process your files one after another in a loop, calling
FindNextFile to get the next file information.

Hope this helps.
 
Roger,

You will have to call the FindClose function.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Roger said:
When done, is a Close of some sort
needed?
Roger
In this case, you would want to call FindFirstFileEx through the
P/Invoke layer. It will return a handle which represents the search. Then,
you would process your files one after another in a loop, calling
FindNextFile to get the next file information.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


ThisBytes5 said:
Is there a built in way in .net to retrieve all the files in a
directory one at a time? I have to process a bunch of files serially
and there can be more than 100K files in the dir. I am trying to avoid
FileInfo[] or System.IO.Directory.GetCurrentDirectory() as I don't
want all the info loaded into memory at once.

Previously I would just use FindFirst and Findnext

Thanks
Wayne
 
When done, is a Close of some sort
needed?
Roger
In this case, you would want to call FindFirstFileEx through the
P/Invoke layer. It will return a handle which represents the search. Then,
you would process your files one after another in a loop, calling
FindNextFile to get the next file information.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


ThisBytes5 said:
Is there a built in way in .net to retrieve all the files in a
directory one at a time? I have to process a bunch of files serially
and there can be more than 100K files in the dir. I am trying to avoid
FileInfo[] or System.IO.Directory.GetCurrentDirectory() as I don't
want all the info loaded into memory at once.

Previously I would just use FindFirst and Findnext

Thanks
Wayne
 
Back
Top