python学习笔记--backup
上一篇 /
下一篇 2013-09-07 17:41:32
/ 个人分类:PYTHON
#filename: backup.py
import os
import time
# source file and direcotry
source = [r'D:\kankan', r'D:\Kugou']
# target file
target_dir = r'C:\backup\\'
#file name and subdirecotry name
today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
# create the subdirectory if it isn't exist
if not os.path.exists(today):
os.mkdir(today)
print 'successfully created directory'
#name of rar file
target = today + os.sep + now +'.rar'
#rar command
rar_command = r"""C:\Progra~1\WinRAR\Rar.exe a %s %s """%(target,' '.join(source))
print 'rar_command is :',rar_command
if os.system(rar_command)== 0:
print 'successful open rar'
else:
print 'Failed openrar'
1.win7 64bit系统需下载 win7 for winRAR 64bit版本,否则在执行下面的dos命令(C:\Progra~1\WinRAR\Rar.exe a %s %s)不能成功
收藏
举报
TAG: