zip 压缩
zip 压缩文件 (对 10.0 组件 zip 压缩的补充, 组件的 zip 压缩打乱了文件夹的层级关系)
def zip_file(start_dir):
#start_dir 需要压缩的文件夹
file_news = start_dir + '.zip'
z = zipfile.ZipFile(file_news,'w',zipfile.ZIP_DEFLATED)
for dir_path,dir_names,file_names in os.walk(start_dir):
file_path = dir_path.replace(start_dir,'')
file_path = file_path and file_path + os.sep or ''
#当前路径中有文件夹
if len(dir_names) != 0:
for dirname in dir_names:
z.write(os.path.join(dir_path,dirname),file_path+dirname)
for filename in file_names:
z.write(os.path.join(dir_path,filename),file_path+filename)
#当前路径中没有文件夹
else:
for filename in file_names:
z.write(os.path.join(dir_path,filename),file_path+filename)
z.close()
还没有开始运用组件,原来还有这个问题啊,倒是可以提个 BUG 建议修改一下组件功能,代码可以先用着:)等组件功能好了,再换成用组件。
👍