zip error: Could not create output file

loveforeverpt 2015-06-13 04:11:38
各位大神:
我最近模仿网上教程写个备份的脚本,但是结果一直报错,“zip error: Could not create output file ('C:/Users/admin/Desktop/Test/20150613.zip')”,不明原因,麻烦大家指导下,感激不尽!

# -*- coding: UTF-8 -*-
# FileName: BackUp.py

import os
import time

source = 'C:\\my_python_programs'

target_dir = 'C:\\Users\\admin\\Desktop\\Test\\'

target = target_dir + time.strftime('%Y%m%d') + '.zip'

zip_command="zip -qr '%s' %s" % (target,source)

if os.system(zip_command)== 0:
print 'Successful backup to ',target
else:
print 'BackUp Failed'
...全文
2298 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_36447040 2016-10-28
  • 打赏
  • 举报
回复
谢谢,可以了哦
loveforeverpt 2015-06-16
  • 打赏
  • 举报
回复
引用 2 楼 sprawling 的回复:
没有问题哦.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# FileName: E:/py_code/base/test150615.py

import os
import time

source = 'E://py_code//base'

target_dir = 'E://py_code//'

target = target_dir + time.strftime('%Y%m%d') + '.zip'

zip_command="zip -qr '%s' %s" % (target,source)

if os.system(zip_command)== 0:
	print 'Successful backup to ',target
else:
	print 'BackUp Failed'
引用 2 楼 sprawling 的回复:
没有问题哦.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# FileName: E:/py_code/base/test150615.py

import os
import time

source = 'E://py_code//base'

target_dir = 'E://py_code//'

target = target_dir + time.strftime('%Y%m%d') + '.zip'

zip_command="zip -qr '%s' %s" % (target,source)

if os.system(zip_command)== 0:
	print 'Successful backup to ',target
else:
	print 'BackUp Failed'
谢谢,我后来试出问题来了,windows下面的zip_command="zip -qr '%s' %s" % (target,source) ,不能加引号,我把引号去掉就没问题了。
sprawling 2015-06-15
  • 打赏
  • 举报
回复
没有问题哦.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# FileName: E:/py_code/base/test150615.py

import os
import time

source = 'E://py_code//base'

target_dir = 'E://py_code//'

target = target_dir + time.strftime('%Y%m%d') + '.zip'

zip_command="zip -qr '%s' %s" % (target,source)

if os.system(zip_command)== 0:
print 'Successful backup to ',target
else:
print 'BackUp Failed'


  • 打赏
  • 举报
回复
检查目标路径是否存在 是否有系统权限 换成D:\\根目录试试

37,744

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧