Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-removebg-preview (15)

PyTreefy

License Python Buy Me a Coffee

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.

Features

  • 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.

Setup

Requires Python 3.x.

Clone the repository and navigate into it:

git clone https://github.com/infinition/PyTreefy.git
cd PyTreefy

Usage

Run the script and enter the path of the directory you want to analyze when prompted:

python PyTreefy.py

Example

Running 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>

Script Details

  • generate_directory_tree(root_dir): Generates the visual representation of the folder structure.
  • collect_python_scripts(directory): Recurses the directory to find and merge .py files.
  • write_to_output_file(output_file, text): Writes the final string to the output path.

Star History

Star History Chart

License

MIT. See LICENSE.

About

PyTreefy is a Python script designed to explore a specified directory, generate a visual representation of its directory tree, and collect all Python scripts (*.py) present in that directory. The collected scripts are then combined with the directory tree structure and written to an output file.

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages