zip-files

0.4.1 · active · verified Thu Apr 16

The `zip-files` Python library provides command-line utilities, `zip-files` and `zip-folder`, for creating ZIP archives. It offers an easy, platform-independent way to compress files and folders, allowing control over the internal root folder structure and compression method. The current version is 0.4.1, and its release cadence has been infrequent, with the last update in April 2021.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `create_zip_file` function from the programmatic API to generate a ZIP file. It includes creating two dummy files, zipping them into `my_archive.zip` under a specified root folder, and then cleaning up the generated files. The library also provides command-line tools `zip-files` and `zip-folder`.

import os
from zip_files.api import create_zip_file

# Create some dummy files for zipping
with open('file1.txt', 'w') as f:
    f.write('Content of file 1')
with open('file2.py', 'w') as f:
    f.write('print("Hello from file 2")')

output_zip = 'my_archive.zip'
files_to_zip = ['file1.txt', 'file2.py']
root_folder_in_zip = 'my_data'

print(f"Creating {output_zip} with files in root folder '{root_folder_in_zip}'...")
create_zip_file(output_zip, files_to_zip, root_folder=root_folder_in_zip)
print(f"Successfully created {output_zip}")

# You can also use the command-line utility
# import subprocess
# subprocess.run(['zip-files', '-f', 'another_data', 'another_archive.zip', 'file1.txt', 'file2.py'])

# Cleanup (optional)
os.remove('file1.txt')
os.remove('file2.py')
os.remove(output_zip)

view raw JSON →