A fast, feature-rich directory tree printer written in Rust. Displays directory structures with color output, gitignore awareness, and multiple output formats.
Zero external dependencies -- uses only the Rust standard library.
- Color output -- syntax-highlighted file names by extension
- Depth limit -- control how deep to traverse
- File size display -- show human-readable file sizes
- Gitignore-aware -- respects
.gitignorerules automatically - Pattern filtering -- include or exclude files by glob pattern
- Sort options -- sort by name, size, or date
- Hidden files toggle -- show or hide dotfiles
- Multiple output formats -- text (with Unicode tree), JSON, Markdown
- Directory stats -- total files, directories, and size summary
- Dirs/files only -- filter to show only directories or only files
git clone https://github.com/Anuar-boop/tree-printer.git
cd tree-printer
cargo build --release
cp target/release/tree-printer /usr/local/bin/tree-printerOutput:
my-project/
+-- src/
| +-- main.rs
| +-- lib.rs
| +-- utils/
| +-- helpers.rs
+-- tests/
| +-- integration.rs
+-- Cargo.toml
+-- README.md
3 directories, 5 files, 12.4 KB total
# Limit depth to 2 levels
tree-printer -d 2
# Show file sizes
tree-printer -s
# Show hidden files
tree-printer -a
# Sort by file size
tree-printer --sort size
# Show only Rust files
tree-printer --include '*.rs'
# Exclude build artifacts
tree-printer --exclude target --exclude '*.o'
# JSON output
tree-printer --format json > tree.json
# Markdown output
tree-printer --format markdown > TREE.md
# Specific directory
tree-printer /path/to/project -d 3 -s
# Directories only
tree-printer --dirs-only
# Disable color (for piping)
tree-printer --no-color | less
# Ignore gitignore rules
tree-printer --no-gitignore -atree-printer --format json{
"name": "my-project",
"type": "directory",
"children": [
{
"name": "src",
"type": "directory",
"children": [
{
"name": "main.rs",
"type": "file",
"size": 2048
}
]
}
],
"stats": {
"directories": 3,
"files": 5,
"total_bytes": 12680
}
}tree-printer --format markdown -s# my-project/
- **src/**
- main.rs *(2.0 KB)*
- lib.rs *(1.5 KB)*
- **utils/**
- helpers.rs *(856 B)*
- **tests/**
- integration.rs *(1.2 KB)*
- Cargo.toml *(245 B)*
- README.md *(3.4 KB)*
---
*3 directories, 5 files, 12.4 KB total*USAGE:
tree-printer [OPTIONS] [PATH]
ARGS:
[PATH] Directory to print (default: current directory)
OPTIONS:
-d, --depth <N> Maximum depth to display
-s, --size Show file sizes
-a, --all Show hidden files (dotfiles)
--no-color Disable color output
--no-gitignore Don't respect .gitignore rules
--sort <MODE> Sort by: name (default), size, date
--format <FMT> Output format: text (default), json, markdown
--include <PATTERN> Only show files matching pattern (repeatable)
--exclude <PATTERN> Hide files matching pattern (repeatable)
--dirs-only Only show directories
--files-only Only show files
-h, --help Show help message
-v, --version Show version
| Color | File Type |
|---|---|
| Blue (bold) | Directories |
| Green | Source code (.rs, .py, .js, .go, .java, etc.) |
| Yellow | Documentation (.md, .txt, .pdf) |
| Cyan | Config files (.json, .yaml, .toml, .ini) |
| Magenta | Images (.png, .jpg, .svg) |
| Red | Shell scripts (.sh, .bash) |
| Dim | Lock files (.lock, .sum) |