Reader Level:
ARTICLE

Enumerate Files in C#

On July 20, 2012 Articles | Files, Directory, IO
In this article we will discuss about how to Enumerate File in C#.
  • 0
  • 0
  • 7779

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

Free Book

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

Dinesh Beniwal

 I am working as VP Content Manager, responsible for content publishing, content development, and social relation. You can follow me on twitter @dbeniwal21

  • 4rank
  • 4M readers
COMMENT USING

Trending up