通过os模块的system()方法调用了系统的rar.exe命令,这个方法会返回一个变量exit_status。
相关推荐:《Python教程》
import os
import time
source = [r‘D:WorkPythonDemo‘, ‘d:worklinux‘]
target_dir = ‘D:Workbackup‘
target = target_dir + time.strftime(‘%Y%m%d%H%M%S‘) + ‘.rar‘
zip_command = "rar a %s %s" % (target, ‘ ‘.join(source))
if os.system(zip_command) == 0:
print ‘Sucessful backup to‘, target
else:
print ‘Backup Failed‘