ziptools — The Bits That Python's zipfile Forgot

Meet ziptools, a free program and library that lets you create and extract zipfiles on all your devices, using sorely needed tools not available in Python's built-in zipfile support.


ziptools is both an importable module package and a collection of command-line scripts that create and extract zipfiles. It augments Python's zipfile module with crucial missing functionality. Most notable among ziptools' enhancements:

Folders: ziptools adds entire folder trees to zipfiles automatically
Modtimes: ziptools propagates original modtimes for files, folders, and links
Cruft skips: ziptools can either include or skip system "cruft" files on request
Symlinks: ziptools copies or follows symlinks to files and folders on Unix and Windows
Long paths: ziptools supports long pathnames on Windows beyond its normal limits
Permissions: ziptools propagates Unix file-access permissions for all items on request
Timestamps: ziptools fixes DST and timezone skew in modtimes with UTC timestamps

There's more on ziptools' features here. ziptools is also portable—it can create and extract standard-conforming zipfiles on Mac OS, Windows, Linux, Android, and others, and can serve as your sole zip and unzip utility on all these platforms. Simply use the local Python 3.X or 2.X, or install one where needed; ziptools works on either Python.


To get started with ziptools:

The package's main create and extract scripts also come with loads of in-program documentation, as does its importable module used by the scripts.

And yes, ziptools zipped itself like this:

/...code$ python3 $Z/ ziptools -skipcruft
Zipping ['ziptools'] to
Cruft patterns: {'skip': ['.*', '[dD]esktop.ini', 'Thumbs.db', '~*', '$*', '*.py[co]'], 'keep': ['.htaccess']}
Adding folder ziptools
--Skipped cruft file ziptools/.DS_Store
Adding  file  ziptools/.htaccess
Adding  file  ziptools/
Adding folder ziptools/cmdtest
--Skipped cruft file ziptools/cmdtest/.DS_Store
Adding  file  ziptools/cmdtest/_HOW-RUN.txt
Adding  file  ziptools/ziptools/
--Skipped cruft file ziptools/ziptools/ziptools.pyc
Create finished: files=513, folders=264, links=0, unknowns=0, crufts=31.

If you had already installed ziptools, you could unzip its package like this (but use your local unzip tool the first time around):

/$ $Z/ . -permissions
Unzipping from to .
Extracted ziptools/
		=> ziptools
Extracted ziptools/.htaccess
		=> ziptools/.htaccess
Extracted ziptools/
		=> ziptools/
Extracted ziptools/cmdtest/
		=> ziptools/cmdtest
Extracted ziptools/cmdtest/_HOW-RUN.txt
		=> ziptools/cmdtest/_HOW-RUN.txt
Extracted ziptools/ziptools/
		=> ziptools/ziptools/
Extract finished: files=513, folders=264, links=0, unknowns=0.

For info on ziptools command-lines, try this. For examples of other programs that build ziptools command lines on the fly, search for ziptools in genhtml's scripts here and here. And for details on importing and calling ziptools' tools more directly, see its examples and code docs.


Mergeall's version
ziptools is also included as a nested tool in the Mergeall content backup/mirror program, because it was initially developed for testing that system. See its top-level test/ziptools folder if you've already fetched a Mergeall package. The version of ziptools included in Mergeall is that current when Mergeall was packaged, but is likely out of date; the latest version is always here.
Latest upgrades
This program was last changed on April 11, 2020. Its most recent releases feature filename wildcards on Windows; end-of-run statistics; assorted Python 2.X fixes; optional permissions propagation; alternate zip paths; and UTC timestamps. The permissions upgrade is intended for use with zipfiles originating on Unix; learn more about it in 1.1's demos. The UTC-timestamp upgrade neutralizes DST and timezone changes for all items' modtimes by using extra zip fields instead of zip's local time; see it in action in 1.2's demos.

For more code examples, see the programs page.

[Home] Books Programs Blog Python Author Training Search Email ©M.Lutz