#参数为需要压缩的文件夹路径
def zip_ya(start_dir):
file_name = start_dir + '.zip' # 压缩后文件夹的名字
z = zipfile.ZipFile(file_name, 'w', zipfile.ZIP_DEFLATED)
for dir_path, dir_names, file_names in os.walk(start_dir):
f_path = dir_path.replace(start_dir, '') # 这一句很重要,不replace的话,就从根目录开始复制
f_path = f_path and f_path + os.sep or '' # 实现当前文件夹以及包含的所有文件的压缩
for filename in file_names:
z.write(os.path.join(dir_path, filename), f_path + filename)
z.close()
return file_name
12-28
06-15
2841
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-27