python学习笔记--backup

上一篇 / 下一篇  2013-09-07 17:41:32 / 个人分类:PYTHON

这几天在学习python,看的教程是Swaroop, C. H. 著
沈洁元 译《简易python教程》
http://woodpecker.org.cn/abyteofpython_cn/chinese/index.html
 
 
#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:

 

评分:0

我来说两句

Open Toolbar