|
楼主 |
发表于 2017-8-30 14:44:15
|
显示全部楼层
本帖最后由 jerrylee 于 2017-8-30 14:52 编辑
问题已解决了,下面说下我的解决方法吧
1.下载7-Zip并安装(报错原因是当前电脑无zip程序)
2.将安装文件中的7z.exe移至‘C:\Windows’目录下
3.将程序中的 zip_command = "zip -qr '%s' %s"%(target,''.join(source))
改为:zip_command = "7z a %s %s"%(target, ' '.join(source)) 即可
再运行便会发现,文件备份压缩成功啦
附代码
- import os
- import time
- source = [r'D:\tools\python\project\if.py',r'D:\tools\python\project\seq.py']
- target_dir = r'D:\Work\Work'
- target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
- zip_command="7z a %s %s"%(target, ' '.join(source))
- if os.system(zip_command)==0:
- print 'Successful backup to',target
- else:
- print 'Backup Failed'
复制代码 |
|