【发布时间】:2010-03-13 10:45:01
【问题描述】:
#Filename:backup_ver1
import os
import time
#1 Using list to specify the files and directory to be backed up
source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py'
#2 define backup directory
destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse'
#3 Setting the backup name
targetBackup = destination + time.strftime('%Y%m%d%H%M%S') + '.rar'
rar_command = "rar.exe a -ag '%s' %s" % (targetBackup, ''.join(source))
##i am sure i am doing something wrong here - rar command please let me know
if os.system(rar_command) == 0:
print 'Successful backup to', targetBackup
else:
print 'Backup FAILED'
O/P:- Backup FAILED
winrar 也被添加到环境变量下的 Path 和 CLASSPATH - 任何其他有备份目录建议的人都非常欢迎
【问题讨论】:
-
好的,我做到了(导入了 tarfile 模块),它安静地运行——我没有给出任何消息,因为没有添加任何内容来产生消息——我检查了位置 destination=os.path。 join(root,"Documents and Settings","rgolwalkar","Desktop","Desktop","PyDevResourse") 但是没有找到备份。第二个如果我添加:- 如果 os.system(tar) == 0: print 'Successful backup to', targetBackup else: print 'Backup FAILED' --如果 os.system(tar) == 1 会出现错误: TypeError: system() 参数 1 必须是字符串,而不是 TarFile
-
只是好奇,你为什么使用 rar 而不是 python 内置的 zip 等跨平台的东西?
标签: python windows-xp backup rar