Souregi Souregi - 1 year ago 65
C# Question

Getting file by file located in a folder

I got a folder that contains millions and millions of files (under windows server2012), and, using Directory.GetFiles needs a lot of times to get all these files,

I am just wondering if there is any c# method that can return file by file instead of getting all these files at once,

(just like an

and using
while (reader.Read())
to get line by line within DB)

Answer Source
DirectoryInfo di = new DirectoryInfo(yourPath);

foreach (var fi in di.EnumerateFiles())

You can use DirectoryInfo.EnumerateFiles

Returns an enumerable collection of file information in the current directory.

Return Value Type: System.Collections.Generic.IEnumerable<FileInfo>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download