Recursively search directories using Visual C#

Source:

void DirectorySearch(String str2find, String dir)
{
	try
	{
		foreach (String file in Directory.GetFiles(dir, str2find))
			Console.WriteLine(file);
 
		foreach (string directory in Directory.GetDirectories(dir))
		{
			foreach (string file in Directory.GetFiles(directory, str2find))
				Console.WriteLine(file);
			DirectorySearch(str2find, directory);
		}
	}
	catch
	{}
}

Usage:

DirectorySearch("*test*", @"c:\");
Categories: C# Tags: , ,
%d bloggers like this: