python中的压缩、解压包tarfile
来源:互联网 发布:矩阵 线性映射 编辑:程序博客网 时间:2024/05/21 22:51
tarfile是python自带的包,可以直接:import tarfile
对文件进行压缩
import tarfileimport ostar = tarfile.open(r'E:\lxd\test\test123.gz.tar','w')for root, dirs, files in os.walk(r'E:\lxd\test'): for _files in files: if 'pkl' in _files: tar.add(os.path.join(root,_files),arcname=_files)tar.close()
import tarfileimport ostar = tarfile.open(r'E:\lxd\test\test1234.gz.tar','w')for files in os.listdir(r'E:\lxd\test'): if 'pkl' in files: tar.add(os.path.join(root,files),arcname=files)tar.close()
使用with,上下文管理器。
import osimport tarfilewith open(root_path, 'w') as f: for filename in listdir(root_path2): f.add(os.path.join(root_path3,filename), arcname=filename)
将压缩的文件就地解压
t = tarfile.open(r'E:\lxd\test\test1234.gz.tar','r')t.extractall()t.close()
0 0
- python中的压缩、解压包tarfile
- Python中使用tarfile压缩、解压tar归档文件示例
- Python中使用tarfile压缩、解压tar归档文件
- Python 解压压缩包
- Python下使用tarfile模块来实现文件归档压缩与解压
- Python下使用tarfile模块来实现文件归档压缩与解压
- python_使用tarfile压缩及解压的方法
- python tarfile
- 常用压缩包解压
- Python 标准库 -> Zipfile 模块 and Tarfile(tar包)
- python解压压缩包的几种方法
- python解压压缩包的几种方法
- python解压压缩包的几种方法
- 不解压直接读取压缩包中的文件
- python压缩与解压
- python压缩解压
- python tarfile模块
- python tarfile模块
- okHttp架构
- SQL Server基础——T-SQL语句
- java swing 绝对布局
- JAVA面试题
- [RK3288][Android6.0] Ubuntu 编译环境错误小结
- python中的压缩、解压包tarfile
- 使用cmd运行java程序
- c++上机报告
- 简易照相机
- scala入门笔记
- Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version
- 智能指针剖析
- mybatis开发(第三天)
- 关于sublime text3中设置快捷键让html文件在浏览器打开