Shown in zip_demo.py
below is an example on how to zip and unzip directories in Python using shutil
. The script will create a directory called zip_demo_dir
containing a file called temp.txt
, zip it up into a compressed file called zip_demo_output.zip
, and then extract the contents of this zipped file into a directory called zip_demo_output_unpacked
, which will contain a copy of the file temp.txt
.
Note that it is also straightforward to unzip an archive using Python from the command line, as shown below, for example:
>>> import os, shutil
>>> os.listdir()
['example.tar.gz']