# 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:
```bash
git clone https://github.com/ltoscano/pack_the_folder.git
```
Or install via pip:
```bash
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
```python
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:
```python
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](LICENSE) file for more details.
Raw data
{
"_id": null,
"home_page": "https://github.com/ltoscano/pack_the_folder",
"name": "pack-the-folder",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Lorenzo Toscano",
"author_email": "lorenzo.toscano@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3b/88/7ee25fbba9e19a3410f8dfab2afb4d27d819df294304e241a4b2d70e9fe1/pack_the_folder-0.1.1.tar.gz",
"platform": null,
"description": "# pack__the__folder\n\nA 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.\n\n## Description\n\n`pack_the_folder` is a Python library that provides a function to:\n\n- Read the structure of a directory (including nested subdirectories) without file names.\n- Append the content of each file in the directory to the output file, preceded by a comment with the full path of the file.\n- Support a list of allowed file extensions to include.\n- Handle deeply nested folder structures.\n\n## Installation\n\nClone the GitHub repository:\n\n```bash\ngit clone https://github.com/ltoscano/pack_the_folder.git\n```\n\nOr install via pip:\n\n```bash\npip install pack_the_folder\n```\n\n## Features\n\n- Packs the contents of a folder, including all subdirectories, into a single file.\n- Provides a clear \"Folder Tree\" visualization at the beginning of the output file.\n- Separates the folder structure from file contents in the output for better readability.\n- Supports filtering of files based on their extensions.\n- Handles multiple file encodings (UTF-8, Latin-1, UTF-16).\n- Defaults to including only Python files (`.py`) if no extensions are specified.\n- Provides clear structure visualization with indentation for nested directories.\n- Gracefully handles binary files.\n\n## Usage\n\n```python\nfrom pack_the_folder import pack_the_folder\n\n# Pack only Python files (default behavior)\npack_the_folder('input_directory', 'output.txt')\n\n# Pack all files\npack_the_folder('input_directory', 'output.txt', allowed_extensions=[])\n\n# Pack only specific file types\npack_the_folder('input_directory', 'output.txt', allowed_extensions=['.py', '.txt', '.md'])\n```\n\n## Example\n\nSuppose we have the following directory structure:\n\n```\ninput_folder/\n\u251c\u2500\u2500 main.py\n\u251c\u2500\u2500 config.txt\n\u251c\u2500\u2500 subfolder1/\n\u2502 \u2514\u2500\u2500 helper.py\n\u2514\u2500\u2500 subfolder2/\n \u251c\u2500\u2500 data.csv\n \u2514\u2500\u2500 notes.md\n```\n\nIf we run:\n\n```python\npack_the_folder('input_folder', 'output.txt', allowed_extensions=['.py', '.txt', '.md'])\n```\n\nThe `output.txt` file will contain:\n\n```\nFolder Tree:\n===========\n\ninput_folder/\n subfolder1/\n subfolder2/\n\nFile Contents:\n==============\n\n# input_folder/main.py\ndef main():\n print(\"Hello, World!\")\n\nif __name__ == \"__main__\":\n main()\n\n# input_folder/config.txt\n# Configuration file\nDEBUG=True\nLOG_LEVEL=INFO\n\n# input_folder/subfolder1/helper.py\ndef helper_function():\n return \"I'm helping!\"\n\n# input_folder/subfolder2/notes.md\n# Project Notes\n\nRemember to update the documentation.\n\n```\n\nNote that `data.csv` is not included in the output because it doesn't match the allowed extensions.\n\n## Parameters\n\n- **`input_directory`** *(str)*: The path of the input folder.\n- **`output_file`** *(str)*: The full path of the output file.\n- **`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.\n\n## License\n\nThis project is distributed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple Python library to pack the contents of a folder into a single file",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/ltoscano/pack_the_folder"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aec2a3313d9d84a272016fc24b02197c673284a5004328ac01f9a4a4cae97e41",
"md5": "6213f0216d60e34e233ee8b5ea64cf78",
"sha256": "fb5f60dbaf348b9d70eb2868847f06d86d96e82d530e8b428890cb010446cafb"
},
"downloads": -1,
"filename": "pack_the_folder-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6213f0216d60e34e233ee8b5ea64cf78",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5252,
"upload_time": "2024-09-24T22:25:28",
"upload_time_iso_8601": "2024-09-24T22:25:28.855469Z",
"url": "https://files.pythonhosted.org/packages/ae/c2/a3313d9d84a272016fc24b02197c673284a5004328ac01f9a4a4cae97e41/pack_the_folder-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3b887ee25fbba9e19a3410f8dfab2afb4d27d819df294304e241a4b2d70e9fe1",
"md5": "0a17e19929f7e4d1f1b70fd897b355d1",
"sha256": "a39f26f043433d99e142f972deeeea80cd50262cb3d6bdb26d178c952042222f"
},
"downloads": -1,
"filename": "pack_the_folder-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "0a17e19929f7e4d1f1b70fd897b355d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4713,
"upload_time": "2024-09-24T22:25:30",
"upload_time_iso_8601": "2024-09-24T22:25:30.218145Z",
"url": "https://files.pythonhosted.org/packages/3b/88/7ee25fbba9e19a3410f8dfab2afb4d27d819df294304e241a4b2d70e9fe1/pack_the_folder-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-24 22:25:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ltoscano",
"github_project": "pack_the_folder",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pack-the-folder"
}