DEV Community

Water Run
Water Run

Posted on

A Much Better Windows tree Command that Implemented in Rust (tree++)

tree++: A Much Better Windows tree Command

As a 40-year-old software, the functionality of Windows' native tree command has essentially remained stuck in the 1980s:

PS C:\Users\linzh> tree /?
Graphically displays the folder structure of a drive or path.

TREE [drive:][path] [/F] [/A]

   /F   Display the names of the files in each folder.
   /A   Use ASCII instead of extended characters.
Enter fullscreen mode Exit fullscreen mode

The functionality of the only two parameters /F and /A is clearly insufficient. As a tool extremely useful for describing project architecture and writing prompts in today's LLM era, a tree command without even directory exclusion functionality becomes directly unusable when facing modern project build systems with target, node_modules, .vs, etc.

Additionally, it's not particularly fast.

Therefore, over the past half month, I implemented this project with Claude Opus 4.5: tree++: A Much Better Windows tree Command.

And yes, it's written in Rust :-)

Links:

What Makes It Better

More Features: Covers basically all commonly used functions, including advanced features like output to file

Quick reference of tree++ supported parameters:

Option Set (Equivalent Forms) Description
--help -h /? Show help information
--version -v /V Show version information
--ascii -a /A Draw the tree using ASCII characters
--files -f /F Show files
--full-path -p /FP Show full paths
--human-readable -H /HR Show file sizes in human-readable form
--no-indent -i /NI Do not show tree connector lines
--reverse -r /R Sort in reverse order
--size -s /S Show file size (bytes)
--date -d /DT Show last modified date
--exclude -I /X Exclude matching files
--level -L /L Limit recursion depth
--include -m /M Show only matching files
--disk-usage -u /DU Show cumulative directory size
--report -e /RP Show trailing summary statistics
--prune -P /P Prune empty directories
--no-win-banner -N /NB Hide the Windows-native tree banner output
--silent -l /SI Silent terminal output (use with output)
--output -o /O Output results to a file (.txt, .json, .yml, .toml)
--batch -b /B Use batch mode
--thread -t /T Number of scan threads (batch mode, default 8)
--gitignore -g /G Honor .gitignore

Parameters support traditional DOS style, Unix short, and Unix long forms, primarily for compatibility with the original tree command style

Faster: The Rust implementation itself is considerably faster than the old COM-based original; abandoning real-time streaming output (commonly used when outputting to files) allows multi-threaded mode to be even many times faster

Performance comparison (using C:\Windows as an example):

Type Time (ms) Multiplier
tree /f (Windows Native) 20721.90 1.00x
treepp /f 7467.99 2.77x
treepp /f /nb 7392.34 2.80x
treepp /f /nb /b 3226.38 6.42x
treepp /f /nb /b /t 1 9123.00 2.27x
treepp /f /nb /b /t 2 5767.71 3.59x
treepp /f /nb /b /t 4 3948.73 5.25x
treepp /f /nb /b /t 8 3166.81 6.54x
treepp /f /nb /b /t 16 2704.67 7.66x

On this basis, tree++ is fully compatible with the original tree (diff-level output consistency): identical valid commands (excluding failed commands and help commands) produce identical results. This includes boilerplate information (opening volume information, ending no-subfolders information), the original quirky DOS-style paths, tree structure representation, and the behavior of the native /F and /A parameters, etc.

Quick Start

Installation

Download from GitHub Release:

Extract, place in a suitable path, and add to environment variables.

Open Windows Terminal and run treepp /v. If you see the corresponding output, installation is complete.

PS C:\Users\linzh> treepp /v
tree++ version 0.1.0

A much better Windows tree command.

author: WaterRun
link: https://github.com/Water-Run/treepp
Enter fullscreen mode Exit fullscreen mode

Usage

Refer to documentation: Options Documentation

Some simple examples:

  • Basic usage: tree and treepp /f, behaving identically to native
PS D:\data\temp\tempDir> # tree++
PS D:\data\temp\tempDir> treepp
Folder PATH listing for volume Storage
Volume serial number is 26E9-52C1
D:.
└─Tempdir
PS D:\data\temp\tempDir> treepp /f
Folder PATH listing for volume Storage
Volume serial number is 26E9-52C1
D:.
│  TEMP_FILE.txt
│
└─Tempdir
        tempfile.txt

PS D:\data\temp\tempDir> # Native Windows tree
PS D:\data\temp\tempDir> tree
Folder PATH listing for volume Storage
Volume serial number is 26E9-52C1
D:.
└─Tempdir
PS D:\data\temp\tempDir> tree /f
Folder PATH listing for volume Storage
Volume serial number is 26E9-52C1
D:.
│  TEMP_FILE.txt
│
└─Tempdir
        tempfile.txt

PS D:\data\temp\tempDir> # Diff-level identical output
Enter fullscreen mode Exit fullscreen mode
  • Exclude code, output desired information: Using tree++ project directory as example
PS D:\data\Rust\tree++> # Honor .gitignore and exclude .git and .release directories
PS D:\data\Rust\tree++> treepp /f /g /x .git /x .release
Folder PATH listing for volume Storage
Volume serial number is 26E9-52C1
D:.
│  .gitignore
│  Cargo.lock
│  Cargo.toml
│  LICENSE
│  OPTIONS-zh.md
│  OPTIONS.md
│  README-zh.md
│  README.md
│
├─prompts
│      编码规范.md
│
├─src
│      cli.rs
│      config.rs
│      error.rs
│      main.rs
│      output.rs
│      render.rs
│      scan.rs
│
└─tests
        compatibility_test.rs
        functional_test.rs
        performance_test.rs

PS D:\data\Rust\tree++>
Enter fullscreen mode Exit fullscreen mode
  • Change style: Modify style, include size information, remove native boilerplate, etc. (accessing from Desktop)
PS C:\Users\linzh\Desktop> # Same base parameters, change style, access from Desktop
PS C:\Users\linzh\Desktop> treepp D:\data\Rust\tree++ /f /g /x .git /x .release /s /hr /nb /rp
D:\DATA\RUST\TREE++
│  .gitignore        1.7 KB
│  Cargo.lock        18.6 KB
│  Cargo.toml        798 B
│  LICENSE        35.0 KB
│  OPTIONS-zh.md        18.0 KB
│  OPTIONS.md        19.7 KB
│  README-zh.md        4.2 KB
│  README.md        4.6 KB
│
├─prompts
│      编码规范.md        8.6 KB
│
├─src
│      cli.rs        76.4 KB
│      config.rs        50.7 KB
│      error.rs        40.0 KB
│      main.rs        16.5 KB
│      output.rs        32.7 KB
│      render.rs        151.5 KB
│      scan.rs        92.3 KB
│
└─tests
        compatibility_test.rs        58.7 KB
        functional_test.rs        68.0 KB
        performance_test.rs        45.0 KB

3 directory, 19 files in 0.003s
PS C:\Users\linzh\Desktop>
Enter fullscreen mode Exit fullscreen mode
  • Scan C:/Windows and output to file (silent terminal)
PS C:\Users\linzh\Desktop> # Default streaming output to text file
PS C:\Windows> treepp /f /o D:\txt_output.txt /si
PS C:\Users\linzh\Desktop> # Batch mode output to JSON, faster
PS C:\Windows> treepp /f /o D:\txt_output.json /b /si
Enter fullscreen mode Exit fullscreen mode

If this project helps you, please give it a Star to show your support :-)
For any issues, feel free to submit an ISSUE

Top comments (0)