zoukankan      html  css  js  c++  java
  • python备份文件2 分类: python 20130315 15:16 233人阅读 评论(0) 收藏

    #假设存在以下文件夹: D:\keys\miyao.将 keys文件夹中的内容备份

    import os
    import time
    source=[r'D:\keys',r'\miyao']


    target_dir=r'D:\\'


    today=target_dir+time.strftime('%Y%m%d')
    now=time.strftime('%H%M%S')
    comment=raw_input("enter a comment-->")


    print 'comment :',comment
    print len(comment)
    if len(comment)==0:#如果条件成立,则target为 日期\时间.zip
        target=today+os.sep+now+'.zip'
    else:
        target=today+os.sep+now+'_'+\
        comment.replace(' ','')+'.zip'
        print 'target :',target


    print 'today:',today


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


    zip_command='zip -qr %s %s'%(target,''.join(source)) #zip -r 实现对文件夹的备份


    print 'zip_command :',zip_command


    if os.system(zip_command)==0:
        print 'Successful backup to',target


    else:
        print 'Backup Failed'
  • 相关阅读:
    基于bootstrap分页
    encache学习教程
    java异常和spring事务注解
    JSP自定义标签开发入门
    spring junit
    vs与数据库连接查询
    winfrom文本文档打开
    面向对象 封装
    面向对象 概念
    DW 游记代码
  • 原文地址:https://www.cnblogs.com/think1988/p/4628225.html
Copyright © 2011-2022 走看看