This example shows how to get a list of file names from a directory (including subdirectories).
using System.IO; using System; namespace CSharpFilesAndStreams { class Program { static void Main(string[] args) { DisplayImageFiles(); } static void DisplayImageFiles() { DirectoryInfo dir = new DirectoryInfo(@"C:\Windows\Web\Wallpaper"); // Get all files with a *.jpg extension. FileInfo[] imageFiles = dir.GetFiles("*.jpg", SearchOption.AllDirectories); // How many were found? Console.WriteLine("Found {0} *.jpg files\n", imageFiles.Length); // Now print out info for each file. foreach (FileInfo f in imageFiles) { Console.WriteLine("***************************"); Console.WriteLine("File name: {0}", f.Name); Console.WriteLine("File size: {0}", f.Length); Console.WriteLine("Creation: {0}", f.CreationTime); Console.WriteLine("Attributes: {0}", f.Attributes); } } } }