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.
Metadata
Release files for pack-the-folder 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pack_the_folder-0.1.1.tar.gz | 4.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pack_the_folder-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / pack_the_folder-0.1.1.tar.gz
| Download URL | pack_the_folder-0.1.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a39f26f043433d99e142f972deeeea80cd50262cb3d6bdb26d178c952042222f
|
|
BLAKE2b-256 checksum How to use checksums |
3b887ee25fbba9e19a3410f8dfab2afb4d27d819df294304e241a4b2d70e9fe1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / pack_the_folder-0.1.1-py3-none-any.whl
| Download URL | pack_the_folder-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb5f60dbaf348b9d70eb2868847f06d86d96e82d530e8b428890cb010446cafb
|
|
BLAKE2b-256 checksum How to use checksums |
aec2a3313d9d84a272016fc24b02197c673284a5004328ac01f9a4a4cae97e41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for pack-the-folder 0.1.1
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.