New: as of June 2017, there is a new zip-file utility package on this site, with complete, free, and portable scripts for zipping and unzipping files. Check out ziptools for all your zip-file needs; it's an open-source solution to the issues described on this page. With ziptools, a simple "zip-extract.py zipfile destination" command line reliably unzips on Windows and elsewhere, and works around some limitations in other options. The end of this page has more on ziptools.

Windows Explorer Zip Extract Failures


[Dec-2015] A note for Windows users: for reasons still unclear, the zip-file extractor built in to File Explorer in Windows 7 (and perhaps others) may sometimes not work correctly on zip archives like those used for distributing some of the programs on this site. In short, an "Extract All" can silently fail to extract just some of the archive's files, resulting in an incomplete extract which likely won't work as intended.

This is an issue in File Explorer's extractor, not in the zip files themselves. The worst consequence of this issue is indirect: because Windows doesn't generate any sort of warning when it skips files in zip archives this way, the only symptom of this problem is unzipped programs that fail either partially or completely. In other words, this may look like a program failure when it's really an unzip failure! This is so bad that Microsoft probably couldn't have done much more to denigrate zip files if it had tried...

Workarounds

Because of such failures (and others regarding non-ASCII Unicode filenames omitted here), use of Windows' built-in zip extraction is not generally recommended. To address its issues, you can try any of these options:

Unzipping in Python

The latter of the above may be simplest, if you know a modest amount of Python. To unzip this site's PyMailGUI, for example, save its zip file to a folder, "cd" to that folder in a command prompt, and launch python and type code like this (the "pymailgui" extract-to folder is created automatically):

C:\fetchdir> py -3
>>> from zipfile import ZipFile
>>> ZipFile('pymailgui.zip', mode='r').extractall(path='pymailgui')
Alternatively, you can run the required lines in a script file that accepts any zip-file name and extract-to folder as command-line arguments:
File myzip.py

#!/usr/bin/python3
import sys, zipfile 
from zipfile import ZipFile
zipfile.ZipFile(sys.argv[1], mode='r').extractall(path=sys.argv[2])

Command line

C:\Code> myzip.py C:\fetchdir\pymailgui.zip C:\progdir\pymailgui

Naturally, you could also make this a GUI with dialogs for selecting folders, but that is outside this note's scope. If you'd rather avoid the code above, Python's zipfile module also comes with a command-line interface that can be launched with the "-m" argument to locate the module on the usual search path and run it as __main__ (see Learning Python's Appendix A for details):

C:/Code> python -m zipfile -e zipfile.zip target     # Extract zipfile to target folder
C:/Code> python -m zipfile -c zipfile.zip source ... # Create zipfile from sources

For a simple example of creating a zip file with Python—and perhaps freeing yourself from dependence on other zip-file tools altogether—see this example program.

Update: per the note at the top of this page, see also the newer ziptools package, which comes with Python-coded zip and unzip scripts run from simple command lines that can be used as alternatives to other zip tools, including those shipped with Windows and Mac OS. ziptools augments Python's zipfile module with features such as portable symlink support, modtime propagation, and long pathnames on Windows, and is now used to create all the zip files available on this website.



[Home page] Books Code Blog Python Author Train Find ©M.Lutz