如何使用 PowerShell 中的 Tree 命令列出一定级别深度的目录?

Sau*_*cey 4 windows powershell command-line tree

我想使用 Tree 命令列出指定级别的所有目录。我喜欢 Tree 命令排序并使用 ASCII 来显示目录或文件夹以及这些文件夹中的所有文件夹的方式。

这就是我到目前为止所拥有的。我想用 -Depth 2 或类似的东西修改这个命令。这个命令对于列出所有目录非常有用,但我只希望它们下降到一定的级别。我希望这可以帮助你帮助我:)

树| 选择对象-跳过 2 | 设置-内容list20.txt

pos*_*ote 5

正如我们所知,Tree 不是 PowerShell cmdlet,因此不能用于您想要执行的操作。

\n\n

对于你想要的东西,你必须自己写这个或者寻找已经完成的东西。

\n\n

您无法像使用 Get-ChildItem 等那样过滤外部 .exe,而无需使用可用的正常对象遍历工作将其所有输出捕获为对象。

\n\n

如果您搜索此类解决方案,您会遇到以下示例:

\n\n

PowerTip:将 Get-Childitem 限制在树中的有限深度

\n\n
Get-Childitem C:\\Users\\CurlyBlue -include *.docx -depth 2\n
Run Code Online (Sandbox Code Playgroud)\n\n

PowerTip:使用 PowerShell 以树形式查看目录列表

\n\n
Show-Tree e:\\data \xe2\x80\x93depth 2\n
Run Code Online (Sandbox Code Playgroud)\n\n

Powershell目录树

\n\n
get-childitem -Path Q:\\ -Recurse -Directory -Depth 3|select FullName|export-csv C:\\file-tree.csv\n\n\n# or this way\n\n(get-childitem -Path d:\\projects -Recurse -Directory -Depth 2).FullName\n
Run Code Online (Sandbox Code Playgroud)\n\n

还有许多其他选项可以对此进行挖掘。都可以在网上搜索到。

\n\n

例如:\n另请参阅

\n\n

以树状格式列出目录内容,并带有颜色和大量选项

\n