Skip to main content

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pack_the_folder-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

pack_the_folder-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pack_the_folder-0.1.0.tar.gz.

File metadata

  • Download URL: pack_the_folder-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pack_the_folder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a8d5f6d17e9044ae959a3b4c5841e4115214572ba09f1b717e0e2aebd010dcdd
MD5 4568d98a0f7d06e58422a3c78be860ed
BLAKE2b-256 2d00e08e871e2d2970df542b5525ce734ec28a004d2488cff08170758b87abf5

See more details on using hashes here.

File details

Details for the file pack_the_folder-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pack_the_folder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4454cc40107172cb5f2ad7478025eab24da6ee5d304773d2a296aced5fa19b72
MD5 81668f78f769d0bd20b2fe430a2573f8
BLAKE2b-256 49088514f1d6fa44a55500907bd81586320b54c6c8628d7b64f73d2944e47103

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page