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/')
  --version             show program's version number and exit

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.1.tar.gz (3.8 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.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for zipcreator_sebastian_stigler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee010db826d1b0a47e1a6b6dc6f3cefa94fc24084a83744159773a852f45b994
MD5 d66f563fc9457dfd38208581340a57cf
BLAKE2b-256 9e59ebd374e9f67539871fa29b438200d2937dcefdf79f0025ab1556b7227e1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zipcreator_sebastian_stigler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62344b19fc1a830c7a243bfe3359013c613dc3ba13ed5d115006cfff309f9c7d
MD5 2647adb9e67088e076e077a1b8c8ed41
BLAKE2b-256 ae185ded3bb3db74b22cd93c994136fb855563db8ea85fdd43ab3045cf2431cc

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