按c#中的名称搜索文件夹,而不指定路径 [英] Search for a folder by its name in c# without specifying the path
本文介绍了按c#中的名称搜索文件夹,而不指定路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按名称搜索文件夹。但我不知道文件夹的位置。
必须获取该特定文件夹的路径。
我如何做到????
请帮助
I want to search a folder by its name. But i dnt know the location of the folder. Have to get the path of that specific folder. How Can i do it???? Please help
推荐答案
您必须指定搜索文件夹的目录 Directory.GetDirectories Method(String,String,SearchOption)
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);
要从计算机获取所有驱动器,请使用 DircotoryInfo.GetDrives 然后搜索所有可以尝试的:
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));
}
这篇关于按c#中的名称搜索文件夹,而不指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文