本文主要是介绍byteofpython_chn/ch10s02:编写一个Python脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
byteofpython_chn/ch10s02:
备份脚本
# -*- coding: utf-8 -*-#用rar完成备份
import os
import timeMajorObject = [r'E:\eBooks\Linux',r'E:\eBooks\JAVA']
TargetDir = r'E:\eBooks'#
TargetDaily = TargetDir + '\\' + time.strftime('%Y%m%d')
NowTime = time.strftime('%H%M%S')print TargetDailyif not os.path.exists(TargetDaily):os.mkdir(TargetDaily)print 'Successfully created directory ', TargetDailyTarget = TargetDaily + '\\' + NowTime + '.rar'ZipCmd = "rar a -r -m0 \"%s\" %s"%(Target, ' '.join(MajorObject)) #jion方法把MajioObject列表转换为字符串
print ZipCmdresult = os.system(ZipCmd)if 0 == result:print 'Succeed backup to ', Target
else:print 'Backup FAILED. result: %d' % result#rar 命令
# a 增加文件到压缩包
# -r Recurse subdirectories 递归子目录
# -m<0..5> Set compression level (0-store...3-default...5-maximal)
这篇关于byteofpython_chn/ch10s02:编写一个Python脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!