Recursive Directory Search

ForeverZer0 Jun 9th, 2012 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                 /// <summary>
  2.                 /// Recursively searches a directory for filenames using the given filters
  3.                 /// </summary>
  4.                 /// <param name="rootDir">Root directory to begin search</param>
  5.                 /// <param name="filters">Formatted search filters for filenames</param>
  6.                 /// <returns>Collection of files found in root directory and all subdirectories that
  7.                 /// matched the given filter(s).</returns>
  8.                 public static List<string> DirectorySearch(string rootDir, params string[] filters)
  9.                 {
  10.                         List<string> fileList = new List<string>();
  11.                         foreach (string filter in filters)
  12.                                 fileList.AddRange(Directory.GetFiles(rootDir, filter));
  13.                         foreach (string dir in Directory.GetDirectories(rootDir))
  14.                                 fileList.AddRange(DirectorySearch(dir, filters));
  15.                         return fileList;
  16.                 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand