How to unzip specific folder from a .zip with Python

python

Solution

Check `zipfile` module.

For your case:

import zipfile

archive = zipfile.ZipFile('archive.zip')

for file in archive.namelist():
    if file.startswith('foo/'):
        archive.extract(file, 'destination_path')

Problem

I am looking to unzip a particular folder from a .zip in Python: e.g. `archive.zip` contains the folders `foo` and `bar`, I want to unzip `foo` to a specific location, retaining it's folder structure.

Original source

Related problems