无法看到具有所需深度的“树”结构

无法看到具有所需深度的“树”结构

我正在使用 Windows 10,我powershell想查看tree具有所需深度级别的文件夹结构。为此,我使用以下命令:

 tree -F -L 1

但我得出了以下结论:

PS E:\Tutorials> tree -F -L 1
Too many parameters - -L

这里有什么问题?以及查看tree结构的正确方法是什么windows

提前致谢。

答案1

如何在 Powershell 中显示具有指定深度的目录树?

Show-Tree您可以使用PowerShell 社区扩展项目

安装show-tree

> Install-Script -Name Show-Tree

Untrusted repository
You are installing the scripts from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install
 the scripts from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a     

获取帮助show-tree

> get-help show-tree

NAME
    Show-Tree

SYNOPSIS
    Shows the specified path as a tree.


SYNTAX
    Show-Tree [[-Path] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>]

    Show-Tree [[-LiteralPath] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt]
    [<CommonParameters>]


DESCRIPTION
    Shows the specified path as a tree.  This works for any type of PowerShell provider and can be used to explore providers used for configuration like the WSMan provider.


RELATED LINKS

REMARKS
    To see the examples, type: "get-help Show-Tree -examples".
    For more information, type: "get-help Show-Tree -detailed".
    For technical information, type: "get-help Show-Tree -full".

示例输出:

> Show-Tree f:\test –depth 2
F:\test
├──subdir
│  └──child
├──test
├──test with space
│  └──child
└──test.with.dot
   └──child
>

答案2

非常感谢大卫·波斯蒂尔♦为了答案

但这其中有一个问题。

有两种Show-Tree,一种是PowerShell的脚本,一种是Pscx的函数。

  • [PowerShell 脚本] 显示树
    • 安装
      Install-Script -Name Show-Tree
      
    • 句法
      Show-Tree [[-Path] <Object>] [-MaxDepth <Int32>] [-ShowDirectory] [-NotLike <String[]>] [-Like <String[]>] [<CommonParameters>]
      
  • [韋斯特功能]显示树
    • 安装
      Install-Module -Name Pscx -AllowClobber
      
    • 句法
      Show-Tree [[-Path] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>]
      
      Show-Tree [[-LiteralPath] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>]
      

Pscx 的Show-Tree功能更强大,支持显示每个容器中的叶项目。

示例如下:

PS> show-tree C:\Users\jqgsninimo\tree\ -depth 3 -showleaf
C:\Users\jqgsninimo\tree\
├──1
│  ├──2
│  │  ├──3
│  │  └──3.txt
│  └──2.txt
└──1.txt

如果[PS Script] Show-Tree错误安装,可以执行以下命令进行替换。

PS> uninstall-script -name show-tree
PS> Install-Module -Name Pscx -AllowClobber

相关内容