Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用powershell高效地查找具有特定名称的文件夹?_Powershell - Fatal编程技术网

如何使用powershell高效地查找具有特定名称的文件夹?

如何使用powershell高效地查找具有特定名称的文件夹?,powershell,Powershell,我想使用powershell在某个路径中搜索具有特定名称的文件夹,我有: get-childitem -path $path -Recurse -Directory -filter $folderName | foreach{ write-host $_.FullName } 它可以工作,但速度非常慢,因为有很多文件要搜索。我正在处理的情况是,在我想要查找的文件夹中有大量文件。检查所有这些文件是浪费时间。所以我想知道,当文件夹名称与我要搜索的内容匹配时,是否有一种方法可以不深入这个文件

我想使用powershell在某个路径中搜索具有特定名称的文件夹,我有:

get-childitem -path $path -Recurse -Directory -filter $folderName |
foreach{
    write-host $_.FullName
}
它可以工作,但速度非常慢,因为有很多文件要搜索。我正在处理的情况是,在我想要查找的文件夹中有大量文件。检查所有这些文件是浪费时间。所以我想知道,当文件夹名称与我要搜索的内容匹配时,是否有一种方法可以不深入这个文件夹。无法通过删除-recurse标记来完成此操作,因为我要搜索的文件夹不一定只在$path内,可能在某些级别以下


谢谢

假设您可以访问路径中的所有文件夹,您可以使用:

$recurse = [System.IO.SearchOption]::AllDirectories
[System.IO.Directory]::GetDirectories($path,$folderName,$recurse)