Answers for "python extract zip file without directory structure"

1

python zip extract directory

import zipfile

archive = zipfile.ZipFile('archive.zip')

for file in archive.namelist():
    if file.startswith('foo/'):
        archive.extract(file, 'destination_path')
Posted by: Guest on September-20-2020
0

python extract zip file without directory structure

import os
import shutil
import zipfile

my_dir = r"D:\Download"
my_zip = r"D:\Download\my_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)
Posted by: Guest on September-20-2020
0

how to extract zip file using python

ZipFile.extractall(path=None, members=None, pwd=None)
Posted by: Guest on May-19-2020

Code answers related to "python extract zip file without directory structure"

Python Answers by Framework

Browse Popular Code Answers by Language