1import zipfile
2import os
3import sys
4
5def zipfolder(foldername, target_dir):
6 zipobj = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)
7 rootlen = len(target_dir) + 1
8 for base, dirs, files in os.walk(target_dir):
9 for file in files:
10 fn = os.path.join(base, file)
11 zipobj.write(fn, fn[rootlen:])
12
13zipfolder('thenameofthezipfile', 'thedirectorytobezipped') #insert your variables here
14sys.exit()
15