Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python extract zip file without directory structure

import os
import shutil
import zipfile

my_dir = r"D:Download"
my_zip = r"D:Downloadmy_file.zip"

with zipfile.ZipFile(my_zip) as zip_file:
    for member in zip_file.namelist():
        filename = os.path.basename(member)
        # skip directories
        if not filename:
            continue

        # copy file (taken from zipfile's extract)
        source = zip_file.open(member)
        target = open(os.path.join(my_dir, filename), "wb")
        with source, target:
            shutil.copyfileobj(source, target)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #extract #zip #file #directory #structure
ADD COMMENT
Topic
Name
9+7 =