Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unzip specific folder from a .zip with Python

Tags:

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.

like image 904
James Avatar asked Dec 07 '12 14:12

James


1 Answers

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') 
like image 195
kaspersky Avatar answered Oct 24 '22 16:10

kaspersky