Extracting zip file contents to specific directory in Python 2.7

I think you’ve just got a mixup here. Should probably be something like the following:

import zipfile

fh = open('test.zip', 'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
    outpath = "C:\\"
    z.extract(name, outpath)
fh.close()

and if you just want to extract all the files:

import zipfile

with zipfile.ZipFile('test.zip', "r") as z:
    z.extractall("C:\\")

Use pip install zipfile36 for recent versions of Python

import zipfile36

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)