C#: Recursively getting a list of files with a specific extension
How to recursively get a list of files with a specific extension in C#.
Inputs:
sDir – Starting directory
SExtension – file extension to filter by
List files – A empty list that is used to keep found files while recursing.
public List<string> getFiles(string sDir, string sExtension, List<string> files) { foreach (string d in Directory.GetDirectories(sDir)) { foreach (string f in Directory.GetFiles(d)) { if (f.EndsWith(sExtension)) { files.Add(f); } } getFiles(d, sExtension, files); } return files; }
Starting Source:
http://stackoverflow.com/questions/929276/how-to-recursively-list-all-the-files-in-a-directory-in-c
Leave a Reply