Pages

Friday, June 4, 2010

Get filenames from all folders

Here is another way to get filenames from all folders, including subdirectories (notice the SearchOption.AllDirectories parametre):

// Process the list of files found in all directory.


string
[]
fileEntries = Directory.GetFiles(sourceDir,
"*", SearchOption.AllDirectories);


foreach

(string fileName in
fileEntries)


{

// do something with fileName


     
Console.WriteLine(fileName);


}


If you change the "*" to ex. "*.log" you will get all filenames that ends with ".log".

No comments:

Post a Comment