[C#] How to Enumerate Files in C#

The Directory.EnumerateFiles method returns an enumerable collection of file names in the specified directory.

string root = @"C:\Temp";
// Get a list of all subdirectories
var files = from file in Directory.EnumerateFiles(root)select file;
Console.WriteLine("Files: {0}", files.Count().ToString());
Console.WriteLine("List of Files");
foreach (var file in files)
{
    Console.WriteLine("{0}", file);
}

 

Xem thêm  [C#] How to use File.OpenWrite Method

You may also like...

1 Response

  1. Your blog is a new view at an old issue. TY! I will be sharing this!

Leave a Reply

Your email address will not be published. Required fields are marked *