Recurse through a folder to get all filenames in .NET C#

Here's a sample code to follow

using System.IO;

string [] fileEntries = Directory.GetFiles(sourceDir);
foreach(string fileName in fileEntries)
{
// get file information for the file
FileInfo fi = new FileInfo(fileName);
// do something with file info exposed properties
Console.WriteLine(fi.Name);
}

Comments