Created
February 15, 2021 13:48
-
-
Save himaprasoonpt/684e1a6ecaa9c02ca21e8651e2ce48ad to your computer and use it in GitHub Desktop.
Python code snippet to zip a folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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