Last active
August 23, 2022 06:39
-
-
Save jonnyyu/5af4a5779fe1d962fd2e8a9718a89f16 to your computer and use it in GitHub Desktop.
zip a folder with zipfile
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
def zip(zip_file, src_dir): | |
with zipfile.ZipFile(zip_file, 'w') as zipObj: | |
for folderName, subfolders, filenames in os.walk(src_dir): | |
for filename in filenames: | |
# create complete filepath of file in directory | |
filePath = os.path.join(folderName, filename) | |
zipObj.write(filePath, osp.relpath(filePath, src_dir)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment