码迷,mamicode.com
首页 > 编程语言 > 详细

python 练手程序 文件备份

时间:2016-07-02 11:46:01      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

#filename; backup_ver3.py

import os
import time

source = [/home/book/Desktop/happy,/home/book/Desktop/new]

target_dir = /home/book/Desktop/backup

today = target_dir + time.strftime(%Y%m%d)

now = time.strftime(%H%M%S)

comment = raw_input(Enter a comment-->)
if len(comment) == 0:
    target = today + os.sep + now + .zip
else:
    target = today + os.sep + now + _ + comment.replace( ,_) + .zip

if not os.path.exists(today):
    os.mkdir(today)
    print Successfully created directory,today

zip_command = "zip -qr ‘%s‘ %s" % (target, .join(source))
if os.system(zip_command) == 0:
    print Successful backup to %s % target
else:
    print Backup FAILED

 

python 练手程序 文件备份

标签:

原文地址:http://www.cnblogs.com/lixiang-/p/5634992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!