新建ziputil.py
import os
import zipfile
def write_zip_file(output_path, output_name, *input_path):
"""
压缩文件
:param output_path: 输出的路径
:param output_name: 压缩包名称
:param input_path: 压缩的文件夹路径
:return:
"""
dir = os.path.dirname(output_path + os.sep)
if not os.path.exists(dir): os.makedirs(dir)
with zipfile.ZipFile(str(output_path) + os.sep + output_name, 'w', zipfile.ZIP_DEFLATED) as f:
for path in input_path:
for root, dirs, files in os.walk(path):
parent_path = os.path.dirname(path)
for file in files:
os.chdir(parent_path)
file_path = str(root).replace(parent_path, '').lstrip(os.sep) + os.sep + file
f.write(file_path)