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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With