PyTreefy is a Python utility that scans a directory, generates its file structure diagram, and concatenates the contents of all discovered Python files into a single consolidated file. This is useful for code auditing, documentation, or bundling context for language models.
- Directory Tree Generation: Creates an ASCII visual representation of the directory and subdirectory tree structure.
- Source Code Aggregation: Collects and appends the source code of all Python scripts (*.py) found inside the target directory.
- Consolidated Output: Combines both the tree diagram and the source files into a single, clean text file.
Requires Python 3.x.
Clone the repository and navigate into it:
git clone https://github.com/infinition/PyTreefy.git
cd PyTreefyRun the script and enter the path of the directory you want to analyze when prompted:
python PyTreefy.pyRunning the script:
Entrez le chemin du répertoire à explorer: /home/user/projects
The script generates output.txt in the target directory with the following structure:
Arborescence des fichiers:
directory/
subdirectory1/
file1.py
file2.txt
subdirectory2/
file3.py
file4.py
# File: file1.py
# Path: /path/to/directory/subdirectory1/file1.py
<contents of file1.py>
# File: file3.py
# Path: /path/to/directory/subdirectory2/file3.py
<contents of file3.py>
# File: file4.py
# Path: /path/to/directory/file4.py
<contents of file4.py>
generate_directory_tree(root_dir): Generates the visual representation of the folder structure.collect_python_scripts(directory): Recurses the directory to find and merge.pyfiles.write_to_output_file(output_file, text): Writes the final string to the output path.
MIT. See LICENSE.