I want to search a folder by its name. But I don't know the location of the folder.
Have to get the path of that specific folder.
How Can i do it?
I want to search a folder by its name. But I don't know the location of the folder.
Have to get the path of that specific folder.
How Can i do it?
You have to specify the directory to search for the folder using Directory.GetDirectories Method (String, String, SearchOption)
string[] directories = Directory.GetDirectories(@"c:\",
"*",
SearchOption.AllDirectories);
To get all drives from the computer, use DircotoryInfo.GetDrives and then search in all of them you can try:
DriveInfo[] allDrives = DriveInfo.GetDrives();
List<string> directoryList = new List<string>();
foreach (DriveInfo d in allDrives)
{
directoryList.AddRange(Directory.GetDirectories(d.Name , "*", SearchOption.AllDirectories));
}
// Only get subdirectories that begin with the letter "p."
string[] dirs = Directory.GetDirectories(@"c:\", "p*");
Console.WriteLine("The number of directories starting with p is {0}.",dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
Reference - Directory.GetDirectories Method (String, String)
If you dont know the drive then you need to search for all drives by changing the drives available on your system.
the only solution is using recursive search to surf all available folders and sub folders and also to jump access denied paths to have complete list of target result.