New: as of June 2017, there is a new zipfile utility package on this site, with complete, free, and portable scripts for zipping and unzipping files. Check out ziptools for all your zipfile 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.

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 Window's built-in zip extraction is not generally recommended. To address its issues, you can try any of these options:

Unzipping in Python

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 X.

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 zipfile 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 zipfile 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.

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


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