Retrieving files from directory that contains large amount of files

Have you tried EnumerateFiles method of DirectoryInfo class?

As MSDN Says

The EnumerateFiles and GetFiles methods differ as follows: When you
use EnumerateFiles, you can start enumerating the collection of
FileInfo objects before the whole collection is returned; when you
use GetFiles, you must wait for the whole array of FileInfo objects to
be returned before you can access the array. Therefore, when you are
working with many files and directories, EnumerateFiles can be more
efficient.

Leave a Comment