load zipfile python from directory code example
Example 1: python zip folder
import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
Example 2: zip a directory in python
shutil.make_archive(output_filename, 'zip', dir_name)
Example 3: make zipfile from directory py
import zipfile
filePaths = []
for root, directories, files in os.walk("MyDirectoryPath"):
for filename in files:
filePath = os.path.join(root, filename)
filePaths.append(filePath)
z = zipfile.ZipFile("MyDirectoryPathWithZipExt.zip", 'w')
with z:
for file in filePaths:
z.write(file)