加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 递归列出powershell中的目录

发布时间:2020-12-14 04:36:10 所属栏目:Windows 来源:网络整理
导读:参见英文答案 How do I get only directories using Get-ChildItem?15个 你如何在Powershell中递归列出目录? 我试过dir / S但没有运气: PS C:Userssnowcrash dir /Sdir : Cannot find path 'C:S' because it does not exist.At line:1 char:1+ dir /S+
参见英文答案 > How do I get only directories using Get-ChildItem?15个
你如何在Powershell中递归列出目录?

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

PS C:Userssnowcrash> 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读