How to Zip All Files in a Directory in Python using ZipFile! Compressing Files in Python

preview_player
Показать описание

Today we are going to look at how to compress all files in a directory in Python. Hopefully you find this useful! Thanks for watching
Рекомендации по теме
Комментарии
Автор

code enhancement - instead of folder.iterdir() we can zipp all sub folder too by below code -

from pathlib import Path
from zipfile import ZIP_DEFLATED, ZipFile

folder_path = Path("./test")

def zip_dir(zip_name, source_dir):
src_path = folder_path
with ZipFile(zip_name, 'w', ZIP_DEFLATED) as zf:
for file in src_path.rglob('*'):
zf.write(file,


zip_dir("qwerty.zip", folder_path)

gourangasatapathy