import zipfile archive = zipfile.ZipFile('archive.zip') for file in archive.namelist(): if file.startswith('foo/'): archive.extract(file, 'destination_path')
Here is what the above code is Doing:
1. Open the zip file
2. Iterate over the files in the archive
3. If the file starts with ‘foo/’, extract it to the destination path