DirScanner is a CLI tool written in Go that scans a directory and generates a Markdown file containing its tree structure. It supports custom connector styles, pattern-based exclusions, depth limiting, file sizes, and summary statistics.
- Markdown tree output — generates a readable directory tree in Markdown
- Stdout mode — print to terminal instead of a file
- File sizes — optionally display each file's size next to its name
- Summary statistics — append a count of files, directories, and total size
- Hidden file support — dotfiles are skipped by default; opt in with a flag
- Pattern exclusions — exclude entries via glob patterns or a
.dirignorefile - Depth limiting — restrict how deep the scan traverses
- Custom connector styles — change the tree branch symbols
go install github.com/SumitKumar-17/DirScanner@latestScan a directory and write the tree to a Markdown file:
dirscanner <directory> <output.md>Print to stdout (omit the output file, or pass -):
dirscanner <directory>
dirscanner <directory> -dirscanner ./myproject structure.md --sizes# Directory Structure for ./myproject
├── main.go (3.2 KB)
├── scanner.go (2.8 KB)
└── go.mod (180 B)
dirscanner ./myproject structure.md --statsAdds a summary line at the bottom of the output:
**Summary:** 12 files, 4 directories, 48.3 KB total size
Include hidden files (dotfiles)
By default dotfiles and hidden directories are skipped. To include them:
dirscanner ./myproject structure.md --show-hiddenUsing --exclude flags (glob patterns):
dirscanner ./myproject structure.md --exclude "*.txt" --exclude "node_modules"Using a .dirignore file placed in the scanned directory:
# .dirignore
node_modules
*.log
dist
Lines starting with # are treated as comments.
dirscanner ./myproject structure.md --depth 2dirscanner ./myproject structure.md --intermediate "+-- " --last "\`-- " --prefix " " --branch "| "dirscanner ./myproject structure.md --verbose
# or
dirscanner ./myproject structure.md -v| Flag | Default | Description |
|---|---|---|
--sizes |
false |
Show file sizes next to filenames |
--stats |
false |
Append summary (files, dirs, total size) to output |
--show-hidden |
false |
Include hidden files and directories (dotfiles) |
--exclude |
[] |
Glob patterns to exclude (repeatable) |
--depth |
-1 |
Max traversal depth (-1 = unlimited) |
--intermediate |
├── |
Symbol for intermediate tree nodes |
--last |
└── |
Symbol for the last node in a directory |
--prefix |
|
Whitespace prefix for child alignment |
--branch |
│ |
Branch connector for intermediate nodes |
--verbose, -v |
false |
Enable debug logging |
Contributions are welcome! Please open an issue to discuss changes or submit a pull request.
This project is licensed under the MIT License — see the LICENSE file for details.
