zoukankan      html  css  js  c++  java
  • python压缩文件脚本

     zf.py文件

    """
    desc:读取配置文件config.ini压缩sourcepath路径到targetpath
         并可以排除不需要压缩的文件excludefile
    time:2014/4/30 12:03:42
    author:ggh
    """
    
    import zipfile, os, configparser, time
    
    firsttime = time.time();
    config = configparser.ConfigParser()
    config.readfp(open('config.ini'))
    excludefile = config.get('global', 'excludefile')
    ls = excludefile.split(',')
    
    def writeInZip(z, testdir):
        for d in os.listdir(testdir):
            if os.path.isdir(testdir+os.sep+d):
                writeInZip(z, testdir+os.sep+d)
            else:            
                if ls.count(testdir+os.sep+d) == 0:
                    z.write(testdir+os.sep+d)
            
    
    testdir = config.get("global","sourcepath")
    z = zipfile.ZipFile(config.get("global","targetpath"), 'w')
    writeInZip(z, testdir)
    z.close()        
    print ('Zip Success!')
    print (time.time() - firsttime)
    input("
    
    Press the enter key to exit.")
    

      

      

    config.ini

    [global]
    sourcepath = D:Web(.net)
    targetpath = D:Web(.net).zip
    excludefile = D:Web(.net)Web.Config,D:Web(.net)Web(.net)_ln.sln
    

      

  • 相关阅读:
    CSS3---用户界面
    CSS3---媒体查询与响应式布局
    HDU 5285 wyh2000 and pupil
    POJ 2488 A Knight's Journey
    POJ 1067 取石子游戏
    POJ 2777 Count Color
    POJ 3259 Wormholes
    Project Euler 26 Reciprocal cycles
    POJ 2104 K-th Number
    POJ 1013 Counterfeit Dollar
  • 原文地址:https://www.cnblogs.com/lovedeeply/p/3701039.html
Copyright © 2011-2022 走看看