【问题标题】:How to find folders efficiently with specific name using powershell?如何使用powershell有效地查找具有特定名称的文件夹?
【发布时间】:2015-07-22 16:30:01
【问题描述】:

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

get-childitem -path $path -Recurse -Directory -filter $folderName |
foreach{
    write-host $_.FullName
}

它可以工作,但速度很慢,因为要搜索的文件很多。我正在处理的情况是我想自己找到的文件夹中有大量文件。检查所有这些文件是在浪费时间。所以我想知道当文件夹名称与我想要搜索的内容匹配时,是否有办法不挖掘这个文件夹。无法通过删除 -recurse 标记来做到这一点,因为我要搜索的文件夹不一定在 $path 内,但可能在某些级别下。

谢谢!

【问题讨论】:

    标签: powershell


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      相关资源
      最近更新 更多