Last active
June 1, 2023 19:45
-
-
Save MMohan1/0c7b4c51319023dbd37d1c4f6bc5260d to your computer and use it in GitHub Desktop.
recursively Extract zip files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import zipfile | |
import re | |
def extract_nested_zip(zippedFile, toFolder): | |
""" Extract a zip file including any nested zip files | |
Delete the zip file(s) after extraction | |
""" | |
if not os.path.exists(zippedFile): | |
return | |
with zipfile.ZipFile(zippedFile, 'r') as zfile: | |
zfile.extractall(path=toFolder) | |
os.remove(zippedFile) | |
for root, dirs, files in os.walk(toFolder): | |
for filename in files: | |
if re.search(r'\.zip$', filename): | |
fileSpec = os.path.join(root, filename) | |
extract_nested_zip(fileSpec, root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment