create zip without zipfile in python code example
Example 1: how to unzip files using zipfile module python
import zipfile
with zipfile.ZipFile("file.zip","r") as zip_ref:
zip_ref.extractall("targetdir")
Example 2: 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)