看过 简明 python 教程 的帮忙解答:第十章的写一个备份脚本文件,
#!/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 什么原因照成的啊!
最满意答案
是不是路径不存在之类的?还有其他输出吗? 在这句zip_command="zip -qr '%s' %s" %(target,' '.join(source))后面加个 print zip_command 然后把这句拷下来,直接运行看看结果更多推荐
发布评论