Skip to content

Instantly share code, notes, and snippets.

@jonnyyu
Last active August 23, 2022 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnyyu/5af4a5779fe1d962fd2e8a9718a89f16 to your computer and use it in GitHub Desktop.
Save jonnyyu/5af4a5779fe1d962fd2e8a9718a89f16 to your computer and use it in GitHub Desktop.
zip a folder with zipfile
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