dirstructx is a Python package that generates structured representations of a directory. It supports multiple output formats such as JSON, YAML, and tree-like structures, making it useful for documenting project structures or analyzing filesystem layouts.
- Generate directory structures recursively with flexible formatting
- Supports multiple output formats:
json
(machine-readable)yaml
(configuration-friendly)tree
(human-readable)
- CLI Usage for quick execution in the terminal
- Library Usage for integration into Python projects
- Custom Sorting Options:
- List files before directories or directories first
- Sort alphabetically or keep the natural order
To install dirstructx, clone the repository and install dependencies:
git clone https://github.com/muldercw/dirstructx.git
cd dirstructx
pip install -r requirements.txt
Or install via pip
:
pip install dirstructx
You can use dirstructx via CLI or as a Python library.
Run dirstructx
on any directory:
python -m dirstructx /path/to/project --format tree
Available output formats:
python -m dirstructx /path/to/project --format json
python -m dirstructx /path/to/project --format yaml
python -m dirstructx /path/to/project --format tree
To redirect output to a file:
python -m dirstructx /path/to/project --format tree > output.txt
{
"README.md": null,
"setup.py": null,
"src": {
"__init__.py": null,
"main.py": null,
"utils": {
"helpers.py": null,
"formatters.py": null
}
}
}
README.md: null
setup.py: null
src:
__init__.py: null
main.py: null
utils:
helpers.py: null
formatters.py: null
├── README.md
├── setup.py
└── src
├── __init__.py
├── main.py
└── utils
├── helpers.py
└── formatters.py
You can also use dirstructx
in your Python scripts:
from dirstructx import generate_structure
directory_path = "/path/to/project"
structure = generate_structure(directory_path)
print(structure) # Prints the directory structure as a dictionary
To format the output in JSON:
import json
print(json.dumps(structure, indent=4))
Or in YAML:
import yaml
print(yaml.dump(structure, default_flow_style=False))
This project is licensed under the MIT License.
For any issues or feature requests, please open an issue on GitHub.
Happy coding! 🚀