• 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) # 清空临时目录
    

      

  • 相关阅读:
    Asp.net 主题 【2】
    Asp.net 主题 【1】
    登陆验证码
    Ajax进阶
    Ajax
    Django之权限管理
    Django之Form进阶
    Django之知识总结
    Django之form表单认证
    Django之ORM查询复习与cookie
  • 原文地址:https://www.cnblogs.com/alplf123/p/8274770.html
Copyright © 2020-2023  润新知