CMD tree command limit number of levels

前端 未结 6 936
盖世英雄少女心
盖世英雄少女心 2021-02-07 04:18

How do I limit the number of levels that the tree command goes through in Windows? I need to output the results to a text file for work, but because by default the tree command

相关标签:
6条回答
  • 2021-02-07 05:06
    1. Try to download WSL in your Windows system.

    2. In your command prompt:

      bash

    3. Then you can use Linux commands:

      tree -L x(the layer)

    0 讨论(0)
  • 2021-02-07 05:08

    Actually, tree command in DOS does not have the level option. You can refer the manual: tree in windows.

    But, you can use the git bash(this is a tool provided by git when you installed the git on windows) or babun(it's a really good tool for windows user to use the *unix tools) so in this way, you can use the command that @Zhengquan Feng mentioned.

    0 讨论(0)
  • 2021-02-07 05:08

    If you use WSL you can also export the result straight to the Windows clipboard

    • From the WSL Cline, if you don't already have tree installed: sudo apt install tree
    • Then: tree -L 5 | clip.exe (replace 5 with however many levels deep you want)

    That'll bypass saving it to a txt file and go straight to your clipboard for quick pasting into forums, etc.

    0 讨论(0)
  • 2021-02-07 05:12

    You can try this project on Windows :

    https://github.com/MrRaindrop/tree-cli

    Usage:

    use -l levelNumber to specify the path level:

    treee -l 2

    0 讨论(0)
  • 2021-02-07 05:13

    Example 3 levels:

    tree|findstr /v /r /c:"^........│" /c:"^│....... " /c:"^ ....... "
    
    0 讨论(0)
  • 2021-02-07 05:17

    Since I didn't found complete answer here. Here it is:

    Windows CMD doesn't support -L depth levels.

    1. Install CygWin https://www.cygwin.com.
    2. In Cygwin make sure you pick Utilities / Tree package installed.
    3. Open CygWin and navigate to your folder, like cd ../../cygdrive/c/myFolder.
    4. List tree structure and save as result.txt tree -L 3 >result.txt.
    0 讨论(0)
提交回复
热议问题