Last active
September 24, 2018 18:59
-
-
Save pedrovanzella/13fdb296c7b1e481168dfbb502aab4a2 to your computer and use it in GitHub Desktop.
Try to unzip a file in a flat hierarchy
This file contains 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 zipfile | |
import os | |
from typing import List | |
def extract(file: str, path: str=".") -> List[str]: | |
names = [] | |
with zipfile.ZipFile(file) as zip_file: | |
for member in zip_file.namelist(): | |
data = zip_file.read(member) | |
file_name = member.split('/')[-1] | |
if not file_name: | |
continue | |
with open(os.path.join(path, file_name), "wb") as f: | |
f.write(data) | |
names.append(file_name) | |
return names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment