如何使用 PowerShell 或 cmd "dir"获取多个但相似的路径的内容?



例如,我希望"Last"文件夹的内容在下面的结构中。 除前两个级别外,各种路径结构是相同的。

  • C:\zyx-wvu\abc\Level3\Last
  • C:\tsr-qpo\def\Level3\Last
  • C:ml-kji\ghi\Level3\Last

在PowerShell中,我接近:

Get-ChildItem -Path C:*-**   

。但是当我尝试时,它不会返回任何结果(因为它永远不会完成(:

Get-ChildItem -Path C:*-**Level3
Get-ChildItem -Path C:*-**   

只会显示 c:\ 中带有连字符的任何内容后面的第二层中的内容

又名它将显示

c:1-2alpha
c:1-5beta

等。。。

你想要的是

Get-ChildItem -Path C:*-***   

或者更有可能你想要

Get-ChildItem -Path C:*-** -recurse

如果要查找具有相同名称的路径...您可以将它们组合在一起,并提取具有多个发现的任何东西......你没有非常具体地问你想要什么,但这里有一些想法。

get-childitem -Path c:*-*** | group-object -property basename | where count -gt 1 | select -expand group

最新更新