windows – 递归列出powershell中的目录

前端之家收集整理的这篇文章主要介绍了windows – 递归列出powershell中的目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > How do I get only directories using Get-ChildItem?15个
你如何在Powershell中递归列出目录?

我试过dir / S但没有运气:

PS C:\Users\snowcrash> dir /S
dir : Cannot find path 'C:\S' because it does not exist.
At line:1 char:1
+ dir /S
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\S:String) [Get-ChildItem],ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
在PowerShell中,dir是Get-ChildItem cmdlet的别名.

与-Recurse参数一起使用它以递归方式列出子项:

Get-ChildItem -Recurse

如果您只想要目录而不是文件,请使用-Directory开关:

Get-ChildItem -Recurse -Directory

-Directory开关是为3.0版中的文件系统提供程序引入的.

对于PowerShell 2.0,过滤PSIsContainer属性

Get-ChildItem -Recurse |Where-Object {$_.PSIsContainer}

(PowerShell别名支持参数解析,因此在上面的所有示例中,Get-ChildItem都可以替换为dir)

原文链接:https://www.f2er.com/windows/364226.html

猜你在找的Windows相关文章