Extract files
Tags: #zip #extract #file
Author: Maxime Jublou

Input

Import libraries

1
import zipfile
2
from io import BytesIO
3
import re
Copied!

Model

Function

1
def extract_zip(filepath):
2
i = 0
3
with zipfile.ZipFile(filepath, "r") as zfile:
4
for name in zfile.namelist():
5
if re.search(r'\.zip#x27;, name) is not None:
6
zfiledata = BytesIO(zfile.read(name))
7
with zipfile.ZipFile(zfiledata) as zfile2:
8
for name2 in zfile2.namelist():
9
zfile2.extract(name2, path="../", pwd=None)
10
i=i+1
11
zfile.close()
12
print("Processing Completed. "+str(i)+" file(s) extracted")
Copied!

Output

Extract zip

1
extract_zip('bilans_saisis_20181231.zip')
Copied!
Last modified 2mo ago
Copy link
Edit on GitHub