Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Created January 22, 2021 11:27
Show Gist options
  • Select an option

  • Save adityatelange/b0b81a61db99b357138826df8f037661 to your computer and use it in GitHub Desktop.

Select an option

Save adityatelange/b0b81a61db99b357138826df8f037661 to your computer and use it in GitHub Desktop.
recursively unzip a zip file with python
#!/usr/bin/python3
# og source: https://gist.github.com/JamesPHoughton/0f4f269e93a2b85958d8
from zipfile import ZipFile
def unpack_zip(zipfile='', path_from_local=''):
filepath = path_from_local+zipfile
extract_path = filepath.strip('.zip') + '/'
parent_archive = ZipFile(filepath)
parent_archive.setpassword(pwd=b'pass')
parent_archive.extractall(extract_path)
namelist = parent_archive.namelist()
parent_archive.close()
for name in namelist:
try:
if name[-4:] == '.zip':
unpack_zip(zipfile=name, path_from_local=extract_path)
except:
print('failed on', name)
pass
return extract_path
# you can just call this with filename set to the relative path and file.
path = unpack_zip(filename)
unpack_zip(zipfile='50.zip', path_from_local='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment