Recursive Directory Search

Settembre 17th, 2007

Description: Example of recursively searching a directory and its child directories for a file

Link: http://www.codekeep.net/snippets/c8afe5a0-f23f-45d1-bcf7-7e58e89fac85.aspx

List<string> fileHolder = new List<string>();

void DirSearch(string sDir)
{
        try
	{
	   foreach (string d in Directory.GetDirectories(sDir))
	   {
		foreach (string f in Directory.GetFiles(d, txtFile.Text))
		{
		   fileHolder.Add(f);
		}
		DirSearch(d);
	   }
	}
	catch (System.Exception excpt)
	{
		Console.WriteLine(excpt.Message);
	}
}

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.