Directory Tree Exporter
A powerful command-line tool that generates both flat file lists and ASCII directory trees for any given path, with output in Markdown, JSON, or both formats.
- Dual Output Formats: Generate both structured JSON file lists and human-readable ASCII directory trees
- Flexible Input: Works with directories and individual files
- Multiple Output Options: Write to files, directories, or display to terminal
- Type-Safe: Comprehensive type hints throughout the codebase
- Robust Error Handling: Graceful handling of permissions, missing files, and edge cases
- Zero Dependencies: Pure Python standard library implementation
# Clone or download the repository
cd /path/to/directory
# Run with default settings (creates both JSON and Markdown files)
python dtree.py
# That's it! Check your directory for dtree.json and dtree_tree.md- Python 3.6 or higher
- Clone or download the repository
- Ensure
dtree.pyis executable:chmod +x dtree.py
- (Optional) Install development dependencies:
pip install -r requirements.txt
# Generate both JSON and Markdown for current directory
python dtree.py
# Generate for a specific directory
python dtree.py --input ./src
# Generate for a single file
python dtree.py --input myfile.txt# Specify output location
python dtree.py --output ./exports
# Custom filename
python dtree.py --output tree.md --format md
# Output to specific directory
python dtree.py --output ./docs --format both# Default: both JSON and Markdown
python dtree.py
# Markdown only
python dtree.py --format md
# JSON only
python dtree.py --format json
# Explicit both
python dtree.py --format both| Option | Description | Default |
|---|---|---|
--input PATH |
Path to directory or file to analyze | Current directory |
--output PATH |
Output file or directory path | Current directory |
--format {md,json,both} |
Output format | both |
--help |
Show help message | - |
# Directory Tree
project/ ├── src/ │ ├── main.py │ └── utils.py ├── tests/ │ └── test_main.py ├── README.md └── requirements.txt
{
"files": [
"project/src/main.py",
"project/src/utils.py",
"project/tests/test_main.py",
"project/README.md",
"project/requirements.txt"
]
}This project maintains high code quality standards:
- Type Hints: Full type annotations for better IDE support and error catching
- Error Handling: Comprehensive error handling for edge cases
- Code Style: Follows PEP 8 guidelines
- Testing: Includes development dependencies for testing
# Install development dependencies
pip install -r requirements.txt
# Run type checking
mypy dtree.py
# Format code
black dtree.py
# Lint code
flake8 dtree.pydTree/
├── dtree.py # Main application
├── requirements.txt # Development dependencies
└── README.md # This file
python dtree.py --input ./src --output ./docs --format both
# Creates docs/dtree.json and docs/dtree_tree.md# View current directory structure (legacy behavior with --format md)
python dtree.py --format md
# Creates dtree_tree.md in current directorypython dtree.py --input ./data --format json --output files.json
# Creates a single JSON file with file listingContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run the quality checks:
mypy dtree.py && black dtree.py && flake8 dtree.py - Submit a pull request
Licensed under Apache License 2.0 - see the SPDX header in dtree.py for details.
- Built with Python's excellent standard library
- Inspired by the need for better project documentation tools
- Thanks to the open source community for best practices and tools
Directory Tree Exporter © 2025 Poor Louis Labs - Making project documentation easier, one tree at a time! 🌳