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'
  • 相关阅读:
    map初始化
    map
    sort排序
    455分发饼干
    392判断子序列
    vector遍历
    vector删除数据
    VC-进程间通信(InterProcess Communication,IPC)
    Oracle 11g 安装和登录(windows)
    控制台输出宽字符wchar_t的中文显示问题
  • 原文地址:https://www.cnblogs.com/think1988/p/4628225.html
Copyright © 2011-2022 走看看