ARTICLE

Enumerate Files in C#

Posted by Dinesh Beniwal Articles | Files, Directory, IO July 20, 2012
In this article we will discuss about how to Enumerate File in C#.
Reader Level:

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#

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts