python备份脚本提示文件名,目录或卷标语法出错(Windows7)

#Filename:backup_ver1.py

import os
import time

#1.the files and directories tobe backed up are specified in a list
source=['D:\Library\Pcb','D:\Library\PLD']

target_dir='F:\DD\'

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 back up to',target
else:
print'backup FAILEED'

想把'D:\Library\Pcb,D:\Library\PLD文件备份到f:DD文件夹里,pcb/pld都是文件夹

source=['D:\Library\Pcb','D:\Library\PLD']

target_dir='F:\DD\'
换成这样也不行

这样试试

 source=['D:\\Library\\Pcb','D:\\Library\\PLD']

试过了,我之前的代码就是这个,传上去使得两杆“\" 变成一杆”\"

看过 简明 python 教程 的帮忙解答:第十章的写一个备份脚本文件,
分享| 2011-04-14 14:44 一身平淡 | 浏览 373 次
#!/usr/bin/env python

Filename: backup_ver1.py

import sys
import os
import time

1. The files and directories to be backed up are specified in a list.

source=[r'C:\work1',r'D:\Work']

If you are using Windows, use source=[r'C:\Documents',r'D:\Work'] or something like that

2. The backup must be stored in a main backup directory

target_dir=r'D:\yss' #Remember to change this to what you will be using

3. The files are backed up into a zip file

4. The name of the zip archive is the current date and time

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

5. We use the zip command (in Unix/Linux) to put the files in a zip archive

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

Run the backup

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

我运行后返回的是 Backup FAILED 什么原因照成的啊!
2011-04-14 15:51 #知道最神秘组织让琅琊阁甘拜下风# 提问者采纳
是不是路径不存在之类的?还有其他输出吗?
在这句zip_command="zip -qr '%s' %s" %(target,' '.join(source))后面加个
print zip_command
然后把这句拷下来,直接运行看看结果
追问:
我都建了这些文件夹的
source=[r'C:\work1',r'D:\Work'] 这句的意思:是要把C盘里的work1和D盘的Work备份吗?
target_dir=r'D:\yss' 这句的意思:把要备份的本件夹,将来备份在D盘里的yss文件夹里吗?

按你做的我返回的是:
zip -qr 'D:\yss20110414163016.zip' C:\work1 D:\Work
Backup FAILED

追答:
是啊,你是在windows下吗?
直接在命令行cmd里面输入这条命令看看。很怀疑你的机器上没有zip这个命令呢
追问:
是的,我是在windows下的,你说在命令行里输入这条命令看看,是那条啊?有可能没装zip,能加你QQ聊吗?我的是564332055,非常感谢!!!
追答:
就是zip -qr 'D:\yss20110414163016.zip' C:\work1 D:\Work这条命令

和这个遇到是一样的,可是没解决

http://user.qzone.qq.com/306467355/blog/1456362555
或许这是你想要的答案,可以使用Python标准库zipfile来实现。