def zip_dir(root_path, save_path, title): # use shutil.make_archive in python2.7
rootlength = len(root_path)
z = zipfile.ZipFile(save_path + '/' + title + '.zip',
'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(root_path):
for f in files:
filename = os.path.join(root_path, f)
z.write(filename, filename[rootlength:])
z.close()
评论列表
文章目录