这个备份文件的代码 为什么不能保存呢 老是提示Backup FAILED什么的

你看到我的小熊了吗 2013-05-14 07:34:46
import os
import time
source = ['G:\\1.jpg', 'G:\\2.jpg']
target_dir = 'G:\\'
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
...全文
485 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 angel_su 的回复:
在你脚本文件相同路径下开个控制台窗口,执行上面打印出来的命令,看看是啥结果,有错的的话信息,也不会不会死板板的报Backup FAILED...

import os
import time
source=[r'G:\1.doc']
target_dir='G:\\'
today=target_dir+time.strftime('%Y%m%d')
print today
rar_command = '"C:\Program Files\WinRAR\WinRAR.exe" a %s %s'%(target,' '.join(source))

print 'rar command is',rar_command

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

我放在shell里执行的 错误是: G:\20130514 Traceback (most recent call last): File "C:\Users\Administrator\Desktop\helloworld.py", line 7, in <module> rar_command = '"C:\Program Files\WinRAR\WinRAR.exe" a %s %s'%(target,' '.join(source)) NameError: name 'target' is not defined
angel_su 2013-05-14
  • 打赏
  • 举报
回复
在你脚本文件相同路径下开个控制台窗口,执行上面打印出来的命令,看看是啥结果,有错的的话信息,也不会不会死板板的报Backup FAILED...
  • 打赏
  • 举报
回复
import os import time source = ['G:\\1.jpg', 'G:\\2.jpg'] target_dir = 'G:\\' target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip' zip_command = "zip -qr '%s' %s" % (target, ' '.join(source)) print zip_command if os.system(zip_command) == 0: print 'Successful backup to', target else: print 'Backup FAILED'
  • 打赏
  • 举报
回复
引用 2 楼 angel_su 的回复:
zip_command打印出来看看,顺便在控制台下试试能执行否...
print 出来是这样滴 zip -qr 'G:\20130514195008.zip' G:\1.jpg G:\2.jpg Backup FAILED
  • 打赏
  • 举报
回复
引用 3 楼 angel_su 的回复:
那文件名不能用单引号括起来,有空格的文件名用双引号...
引用 1 楼 go_to_your_mom 的回复:
PS:我是windows用户
我的版本是2.7的 也是这样嘛
angel_su 2013-05-14
  • 打赏
  • 举报
回复
那文件名不能用单引号括起来,有空格的文件名用双引号...
引用 1 楼 go_to_your_mom 的回复:
PS:我是windows用户
angel_su 2013-05-14
  • 打赏
  • 举报
回复
zip_command打印出来看看,顺便在控制台下试试能执行否...
  • 打赏
  • 举报
回复
PS:我是windows用户

37,743

社区成员

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

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