Answers for "zipfile read files from a directory python"

1

make zipfile from directory py

import zipfile
filePaths = [] # Make an array string with all paths to files
for root, directories, files in os.walk("MyDirectoryPath"): # Scans for all subfolders and files in MyDirectoryPath
        for filename in files: # loops for every file
            filePath = os.path.join(root, filename) # Joins both the directory and the file name
            filePaths.append(filePath) # appends to the array
z = zipfile.ZipFile("MyDirectoryPathWithZipExt.zip", 'w')
with z:
    for file in filePaths: # Loops for all files in array
        z.write(file) # Writes file to MyDirectoryPathWithZipExt.zip
Posted by: Guest on January-21-2021
0

get file in file zip python

from zipfile import ZipFile
import os
def getfilespath(filename):
    dir = os.path.dirname(__file__)
    return os.path.join(dir, filename) 
path =  getfilespath("bbc-fulltext.zip")
archive = ZipFile(path, 'r')
files = archive.namelist()
Posted by: Guest on August-14-2021

Code answers related to "zipfile read files from a directory python"

Python Answers by Framework

Browse Popular Code Answers by Language