Skip to main content

PrintDirTree

printdirtree is a command-line utility that prints the structure of a directory tree, allowing you to easily specify files and directories to exclude.

You can now also print the contents of all files, which is very useful for prompting LLMs.

Example:

$ printdirtree
PrintDirTree
├── MANIFEST.in
├── README.md
├── printdirtree
│   ├── __init__.py
│   └── __main__.py
└── setup.py

This tool is very useful to aid with prompting ChatGPT.

Installation

Install printdirtree easily with pip:

pip install printdirtree

Usage

To use printdirtree, simply run the command followed by optional arguments to tailor the output to your needs. The basic usage prints the current directory structure:

printdirtree

Specifying a Directory

To print the structure of a specific directory:

printdirtree --dir /path/to/directory

Excluding Directories and Files

Exclude specific directories and/or file patterns:

printdirtree --exclude-dir node_modules --exclude-dir .git --exclude-file "*.log"

Saving Preferences

To save your exclusions for future runs:

printdirtree --exclude-dir temp --exclude-file "*.tmp" --save

Viewing Current Exclusions

See what exclusions are currently saved:

printdirtree --view-exclusions

Including Directories and Files Back

To remove exclusions and include directories or files back into the printout:

printdirtree --include-dir temp --include-file "*.tmp" --save

Showing File Contents

To display both the directory structure and the contents of all files:

printdirtree --show-contents

This will output the directory tree followed by each file's contents with its relative path as a comment. For example:

temp
├── a.py
└── b.py

# temp/a.py
print("a.py")

# temp/b.py
print("b.py")

This is particularly useful when sharing code with LLMs, as it provides both structure and content in a clear, readable format.

Example Usage

After installing printdirtree, you can run it to visualize the structure of your project directory. Here's an example command that excludes .git files:

printdirtree --exclude-file ".git"

Output for the PrintDirTree project might look like this:

PrintDirTree
├── MANIFEST.in
├── README.md
├── printdirtree
│   ├── __init__.py
│   └── __main__.py
└── setup.py

Metadata

Release files for printdirtree 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for printdirtree 0.1.5
File Size Uploaded Provenance
printdirtree-0.1.5.tar.gz 5.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for printdirtree 0.1.5
File Interpreter ABI Platform
printdirtree-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / printdirtree-0.1.5.tar.gz

Download URL printdirtree-0.1.5.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5a88fdbc83bd107ccc700c9de47147c78d4dfa97f497a3b8b117af021320e3d2
BLAKE2b-256 checksum
How to use checksums
bf894a6b7e981bf75022a5f5b935becc872de3b57019c40c653995b220e83887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Release files / printdirtree-0.1.5-py3-none-any.whl

Download URL printdirtree-0.1.5-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
797347dcb3e03f2b5d471a56b6e93ef0573cbfd42276eeaa9b7bb153d2e2bfbd
BLAKE2b-256 checksum
How to use checksums
da5bb787264aada3ac40e1fd99e8111ce4f15c7ceab3a7e3f4200c3306125223
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Security for printdirtree 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page