Skip to content

Instantly share code, notes, and snippets.

@himaprasoonpt
Created February 15, 2021 13:48
Show Gist options
  • Save himaprasoonpt/684e1a6ecaa9c02ca21e8651e2ce48ad to your computer and use it in GitHub Desktop.
Save himaprasoonpt/684e1a6ecaa9c02ca21e8651e2ce48ad to your computer and use it in GitHub Desktop.
Python code snippet to zip a folder
import os
import zipfile
def zip_dir(folder_path, zip_name):
"""
:param folder_path: Folder path which has to be zipped
:param zip_name: the detsinatio zip name
:return:
"""
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(folder_path):
for file in files:
zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(folder_path, '..')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment