.NET doesn't have a recursive file finding class, so I've used this helper a couple of times:
///
/// Finds a list of files that match the specified critiria
///
public class FileFinder
{
private Dictionary<FileInfo,int> files;
///
/// Returns all files that match MatchType that are children of StartDir
///
///
///
///
public List<FileInfo> Find(string startDir, string matchType)
{
files = new Dictionary<FileInfo, int>();
findFiles(startDir, matchType);
return files.Keys.ToList();
}
private void findFiles(string startDir, string matchType)
{
DirectoryInfo d = new DirectoryInfo(startDir);
foreach (FileInfo f in d.GetFiles(matchType))
{
if (!files.ContainsKey(f))
{
files.Add(f, 0);
}
}
if (d.GetDirectories().Length > 0)
{
foreach (DirectoryInfo subD in d.GetDirectories())
{
findFiles(subD.FullName, matchType);
}
}
}
}
FileFinder fFinder = new FileFinder();
List<FileInfo> files = fFinder.Find("C:\\","*.dll");