Reader Level:
Files, Directory, IO

Enumerate Files in C#

By Dinesh Beniwal on Jul 20 2012
In this article we will discuss about how to Enumerate File in C#.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 17.6k
  • 0

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;
.WriteLine("Files: {0}", files.Count<string>().ToString());
.WriteLine("List of Files");
(var file in files)
    Console.WriteLine("{0}", file);

Free Book

Download Complete free book here: Working with Directories in C#