zoukankan      html  css  js  c++  java
  • tarfile zipfile bz2 gz

    import tarfile
    import os, shutil
    filepath = 'd:/python project'
    ftarname = './test.tar.gz'
    tarlib = './test/'
    print(os.getcwd())
    #==================gz压缩文件===================
    # with tarfile.open(ftarname, mode='w:gz') as tfp:
    #     for file in os.listdir(filepath):
    #         if os.path.isfile(file):
    #             print('compressing file->', file)
    #             tfp.add(file)
    # #=================获取压缩所有文件名============
    # # with tarfile.open(ftarname, mode = 'r:gz') as tfp:
    # #     for name in tfp.getnames():
    # #         print(name)
    #
    # #=================解压所有文件===================
    # with tarfile.open(ftarname, mode = 'r:gz') as tfp:
    #     if not os.path.exists(tarlib):
    #         os.mkdir(tarlib)
    #     for mem in tfp.getmembers():
    #         print('decompressing file->', mem.name)
    #         tfp.extract(mem, tarlib)
    # 当然也可以用extractall 全部解压 类似的还有bz2
    #shutil.rmtree(tarlib) # 清空临时目录
    

      

  • 相关阅读:
    数据持久化的基础知识
    svn常用命令
    关于SVN 目录结构
    linux查看CPU信息
    一个服务器上启动两台tomcat
    centos6.0 配置SVN
    mysql插入表情
    MAC 安装 PIL
    安装freetype
    Hadoop基本文件命令
  • 原文地址:https://www.cnblogs.com/alplf123/p/8274770.html
Copyright © 2011-2022 走看看