Skip to main content

A tool to explore and visualize directory structures

Project description

Directure = Directory + Structure

Motivation
I created this tool after struggling to explain project structures and errors to ChatGPT. It was difficult to clearly communicate my project's directory structure and file contents. With this tool, you can easily generate a visual representation of your project's directory structure, including file contents if desired, which can then be shared or used to debug with AI models like ChatGPT.

Features

  • Visualize Directory Structure: Print the entire directory structure of your project.
  • Include File Contents: Optionally append the contents of specific files or directories to the output for detailed exploration.
  • Ignore List: Specify files and folders to ignore while exploring the structure.
  • Full Explore List: Define directories for detailed exploration and file content output.
  • Write Output to File: Generate an output file containing the directory structure and selected file contents.

Usage

Run directure.py from the command line with several options:

python directure.py [options]

Options:

  • -w: Writes the directory structure and contents to an output file structure.txt.
  • --explore "path/to/directory": Limits exploration to a specific directory or set of directories/files.
  • Directories or files can be ignored by listing them after the main command.

Example Usage

Given the following sample directory structure:

project_root/
│-- src/
│   │-- app.py
│   │-- utils.py
│-- docs/
│   │-- README.md
│-- tests/
    │-- test_app.py
    │-- test_utils.py

1. Default Behavior:

Running the script with no additional flags will print the entire directory structure, ignoring the default ignore list (e.g., venv, __pycache__, .git).

python directure.py

Output:

|-- project_root
    |-- src
        |-- app.py
        |-- utils.py
    |-- docs
        |-- README.md
    |-- tests
        |-- test_app.py
        |-- test_utils.py

2. Writing Output to File:

You can save the structure and file contents into a file by using the -w flag.

python directure.py -w

This will create structure.txt in the current directory, containing:

Directory Structure:

|-- project_root
    |-- src
        |-- app.py
        |-- utils.py
    |-- docs
        |-- README.md
    |-- tests
        |-- test_app.py
        |-- test_utils.py


File Contents:

----------------------------------------
Content of app.py:

<file content>

----------------------------------------
Content of utils.py:

<file content>

----------------------------------------
Content of README.md:

<file content>

----------------------------------------
Content of test_app.py:

<file content>

----------------------------------------
Content of test_util.py:

<file content>

...

3. Exploring a Specific Directory:

To explore only a specific directory or file, use the --explore flag followed by the directory path. For example:

python directure.py --explore "src"

Output:

|-- project_root
    |-- src
        |-- app.py
        |-- utils.py
    |-- docs
    |-- tests

4. Exploring a Directory and Writing to File:

You can combine the --explore flag with the -w flag to write the structure and contents of the explored directory to the output file.

python directure.py --explore "src" -w

This will create or overwrite the structure.txt file with the content from the src directory only.


Default Ignore List

By default, the following directories and files are ignored:

  • venv
  • __pycache__
  • .git

You can extend this list by adding items as arguments when running the script.


How It Works

  • print_directory_structure(path, ignore_list, full_explore_list): Recursively prints the directory structure, ignoring any directories or files on the ignore list and optionally fully exploring directories on the explore list.

  • write_file_contents(path, ignore_list, full_explore_list): Appends the contents of files in explored directories to the output.

  • write_structure_and_contents(directory_path, ignore_list, output_filename, full_explore_list): Combines the directory structure and file content writing functionalities into a single output file.


You can use this tool to generate a clean, structured output of your project that you can share or use for troubleshooting with AI tools.


Further Resources

For more details, check out our Github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

directure-0.1.4.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

directure-0.1.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file directure-0.1.4.tar.gz.

File metadata

  • Download URL: directure-0.1.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for directure-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2cec7edb4db66666f884816f38884ec7894b138eb15b957d2591dd70072bca29
MD5 7303f13878abf879a9452dbece8e432e
BLAKE2b-256 bbd1c4092d32c6ff329bc239b7c72d049efd55b9b0a3fef300628236a17b5a25

See more details on using hashes here.

File details

Details for the file directure-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: directure-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for directure-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1ed5c82ce1b905b333e7c28379dedc15f425ef99dd89fa0f5ca795df3ff7f09e
MD5 449cb98a8abb4e37f1503c62ca48c613
BLAKE2b-256 922f0717ba1fbc31ce359fac25875e2722ca1491b3941c48e6c3a1b4e1a2bcc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page