A simple Python library to pack the contents of a folder into a single file
Project description
pack__the__folder
A simple Python library to pack the contents of a folder into a single file. Particularly useful when you need to condense multiple text files (including source code) into a single file usable with LLMs that handle large context memories.
Description
pack_the_folder
is a Python library that provides a function to:
- Read the structure of a directory (including nested subdirectories) without file names.
- Append the content of each file in the directory to the output file, preceded by a comment with the full path of the file.
- Support a list of allowed file extensions to include.
- Handle deeply nested folder structures.
Installation
Clone the GitHub repository:
git clone https://github.com/ltoscano/pack_the_folder.git
Or install via pip:
pip install pack_the_folder
Features
- Packs the contents of a folder, including all subdirectories, into a single file.
- Provides a clear "Folder Tree" visualization at the beginning of the output file.
- Separates the folder structure from file contents in the output for better readability.
- Supports filtering of files based on their extensions.
- Handles multiple file encodings (UTF-8, Latin-1, UTF-16).
- Defaults to including only Python files (
.py
) if no extensions are specified. - Provides clear structure visualization with indentation for nested directories.
- Gracefully handles binary files.
Usage
from pack_the_folder import pack_the_folder
# Pack only Python files (default behavior)
pack_the_folder('input_directory', 'output.txt')
# Pack all files
pack_the_folder('input_directory', 'output.txt', allowed_extensions=[])
# Pack only specific file types
pack_the_folder('input_directory', 'output.txt', allowed_extensions=['.py', '.txt', '.md'])
Example
Suppose we have the following directory structure:
input_folder/
├── main.py
├── config.txt
├── subfolder1/
│ └── helper.py
└── subfolder2/
├── data.csv
└── notes.md
If we run:
pack_the_folder('input_folder', 'output.txt', allowed_extensions=['.py', '.txt', '.md'])
The output.txt
file will contain:
Folder Tree:
===========
input_folder/
subfolder1/
subfolder2/
File Contents:
==============
# input_folder/main.py
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
# input_folder/config.txt
# Configuration file
DEBUG=True
LOG_LEVEL=INFO
# input_folder/subfolder1/helper.py
def helper_function():
return "I'm helping!"
# input_folder/subfolder2/notes.md
# Project Notes
Remember to update the documentation.
Note that data.csv
is not included in the output because it doesn't match the allowed extensions.
Parameters
input_directory
(str): The path of the input folder.output_file
(str): The full path of the output file.allowed_extensions
(list, optional): List of allowed file extensions. If not specified, defaults to['.py']
. If an empty list is provided, all files will be included.
License
This project is distributed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pack_the_folder-0.1.1.tar.gz
.
File metadata
- Download URL: pack_the_folder-0.1.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a39f26f043433d99e142f972deeeea80cd50262cb3d6bdb26d178c952042222f |
|
MD5 | 0a17e19929f7e4d1f1b70fd897b355d1 |
|
BLAKE2b-256 | 3b887ee25fbba9e19a3410f8dfab2afb4d27d819df294304e241a4b2d70e9fe1 |
File details
Details for the file pack_the_folder-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pack_the_folder-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb5f60dbaf348b9d70eb2868847f06d86d96e82d530e8b428890cb010446cafb |
|
MD5 | 6213f0216d60e34e233ee8b5ea64cf78 |
|
BLAKE2b-256 | aec2a3313d9d84a272016fc24b02197c673284a5004328ac01f9a4a4cae97e41 |