def convert_zip(dir_path):
"""
压缩指定文件夹
:param dir_path: 目标文件夹路径
:return:
"""
out_full_name = dir_path + '.zip'
file_zip = zipfile.ZipFile(out_full_name, "w", zipfile.ZIP_DEFLATED)
for path, dir_names, filenames in os.walk(dir_path):
f_path = path.replace(dir_path, '')
for filename in filenames:
file_zip.write(os.path.join(path, filename), os.path.join(f_path, filename))
file_zip.close()
# 有需求的可以不删除原文件夹
if os.path.exists(out_full_name):
shutil.rmtree(dir_path)
python 压缩指定文件夹
最新推荐文章于 2023-05-25 11:29:12 发布