Home
Manage Your Code
Snippet: Recursive Directory Search (C#)
Title: Recursive Directory Search Language: C#
Description: Example of recursively searching a directory and its child directories for a file Views: 2961
Author: James Taylor Date Added: 9/17/2007
Copy Code  
1List<string> fileHolder = new List<string>();
2
3void DirSearch(string sDir) 
4{
5        try	
6	{
7	   foreach (string d in Directory.GetDirectories(sDir)) 
8	   {
9		foreach (string f in Directory.GetFiles(d, txtFile.Text)) 
10		{
11		   fileHolder.Add(f);
12		}
13		DirSearch(d);
14	   }
15	}
16	catch (System.Exception excpt) 
17	{
18		Console.WriteLine(excpt.Message);
19	}
20}