Skip to main content

Creates a zip archive, excluding files matching .zipignore patterns, and adds a prefix inside the archive

Project description

Zip Creator with Ignore Support

This Python script creates a zip archive of a folder while respecting an ignore file (similar to .gitignore). It also supports adding a prefix to all files inside the archive, similar to git archive --prefix.

Features

  • Exclude files and folders using a .zipignore file (or a custom ignore file)
  • Add an optional prefix inside the zip
  • Command-line interface for easy use

Installation

Ensure you have Python >= 3.10 installed and install it with pipx:

pipx install zipcreater-sebastian-stigler

Usage

zipcreator [-h] [-o OUTPUT_ZIP] [--ignore-file IGNORE_FILE] [--prefix PREFIX] source_folder


positional arguments:
  source_folder         Folder to zip

options:
  -h, --help            show this help message and exit
  -o OUTPUT_ZIP, --output_zip OUTPUT_ZIP
                        Output zip file name (default: archive.zip)
  --ignore-file IGNORE_FILE
                        Ignore file (default: .zipignore)
  --prefix PREFIX       Prefix inside the zip (e.g., 'myproject/')

Examples

1. Basic Usage

zipcreator my_folder -o output.zip

This zips my_folder into output.zip, using .zipignore within my_folder to exclude files.

2. Add a Prefix

zipcreator my_folder -o output.zip --prefix myproject/

This adds myproject/ as a prefix inside the zip.

3. Use a Custom Ignore File

zipcreator my_folder -o output.zip --ignore-file custom.ignore

This uses custom.ignore instead of .zipignore. (The file has to be stored in my_folder.)

Example .zipignore File

# Ignore log files
*.log

# Ignore temporary files
*.tmp
*.bak

# Ignore folders
node_modules/
venv/

# Ignore specific files
secrets.env
debug-output.txt

# Ignore system files
.DS_Store
Thumbs.db

# Ignore __pycache__ directories
__pycache__/

# Ignore build outputs
build/
dist/

# Allow a specific file inside an ignored folder
!dist/readme.txt

Example Output with --prefix myproject/

If your original my_folder structure is:

my_folder/
│── file1.txt
│── file2.log
│── subdir/
│   └── nested.txt

And .zipignore contains:

*.log

Then output.zip will contain:

myproject/file1.txt
myproject/subdir/nested.txt

(file2.log is ignored due to .zipignore)

Licence

MIT Licence

Credit

Created with ChatGPT.

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

zipcreator_sebastian_stigler-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zipcreator_sebastian_stigler-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for zipcreator_sebastian_stigler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aebcb29544b100846dfb7c6c45c21dfe46db69986db8bde85ea6570e525b7cd1
MD5 7a84a545da501436e44b6a350321fef1
BLAKE2b-256 f962a871c68659289d7bc073987df7c853326da493e300b02407a608821f577a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zipcreator_sebastian_stigler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20996ae13959c8b414bdf7be594d933c4161dabac5a23f7a44491d5da0192305
MD5 37a6abb04257951319758126e6c5f14b
BLAKE2b-256 e6ee14a5bebc5f88c6e3aa8b98fd700abbc157deb2b6d2ec93671f3e0ab1c227

See more details on using hashes here.

Supported by

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