Unzip all files to Directory using Python Zipfile

Extract Files from Zip Archive to Folder – Unzip

Use this code to extract or unzip all the files in a Zip file. The files will be extracted to a folder with actual directory structure in one go.

Just like adding files to a Zip archvie this code also uses the ‘Zipfile’ Python open source library.

#Import Libraries
import zipfile

#Directory path to extract files
dirpath = 'E:\OneDrive\Working\itKeyin\ArchiveUnzip'

#Create Zipfile object to process the Archive file.
with zipfile.ZipFile('E:\OneDrive\Working\itKeyin\Archive.zip', 'r') as unzipObject:

    #Extract all files in one Go
    unzipObject.extractall(dirpath)

print ("All files in Zip archive are extracted")

Just replace the directory path and Zip file path in the above code. Then run the code & verify the destination path.

All the files in the archive will be extracted to the given destination path.

If you would like to learn how to Zip a file in Python – Click here.

External Reference: Discussion on how to unzip files from a directory – click here.