Python zipfile – Extracting all members of a zip file

In this post we will be creating a script that will extract all members of a zip file, to do this we will be using the zipfile module that provides tools to create, read, write, append, and list a ZIP file.

We begin by defining the location of our zip folder, using a for a loop we then iterate over the files within the zip folder. Using the ‘extractall’ we extract all members from the zip file to our specified directory.

Full souce code can be found below.

import zipfile

archive = zipfile.ZipFile(r'C:\Downloads\New')

for file in archive.namelist():
    archive.extract(file, r'C:\Desktop')

Leave a Reply