A Python Script to Collect Directory Contents and Generate a Tree Structure

Hi everyone,
I wanted to share my open-source tool I created called dir-to-txt that can greatly enhance your collaboration with chatbots like ChatGPT and Claude when working on coding projects.

The script does the following:

  1. Recursively traverses a specified directory and its subdirectories.
  2. Collects the contents of code files and combines them into a single text file.
  3. Generates a visual directory tree structure in the output file.
  4. Allows filtering files by type, so you can include only relevant code files (e.g., .py, .js, .cpp).
  5. Supports excluding specific files and directories from the output.

By running the script on your project directory, you can generate a compact representation of your codebase in a single text file. This makes it much easier to share your code with chatbots like ChatGPT and Claude, as you can simply copy and paste the contents of the generated file into the chat interface.

The script is available on github: https://github.com/mszabolcs03/dir-to-txt

Feel free to check out the repository, star it if you find it useful, and contribute if you have any ideas for improvements or new features. The repository includes a detailed README file with instructions on how to use the script.

I hope this script enhances your collaboration with ChatGPT, Claude, and other AI assistants in your coding projects. If you have any questions or feedback, please let me know in the comments below.

Happy coding!

submitted by /u/mszabol
[link] [comments]


Posted

in

by

Tags: