Python下使用tarfile模块来实现文件归档压缩与解压
来源:互联网 发布:古代兵器知乎 编辑:程序博客网 时间:2024/06/05 22:40
Python下使用tarfile模块来实现文件归档压缩与解压
部分转自:http://www.diybl.com/course/3_program/python/20110510/555345.html
Tarfile.open(cls, name=None, mode='r', fileobj=None, bufsize=10240, **kwargs) method of __builtin__.type instance
Open a tar archive for reading, writing or appending. Return
an appropriate TarFile class.
mode:
'r' or 'r:*' open for reading with transparent compression
'r:' open for reading exclusively uncompressed
'r:gz' open for reading with gzip compression
'r:bz2' open for reading with bzip2 compression
'a' or 'a:' open for appending, creating the file if necessary
'w' or 'w:' open for writing without compression
'w:gz' open for writing with gzip compression
'w:bz2' open for writing with bzip2 compression
'r|*' open a stream of tar blocks with transparent compression
'r|' open an uncompressed stream of tar blocks for reading
'r|gz' open a gzip compressed stream of tar blocks
'r|bz2' open a bzip2 compressed stream of tar blocks
'w|' open an uncompressed stream for writing
'w|gz' open a gzip compressed stream for writing
'w|bz2' open a bzip2 compressed stream for writing
1.压缩,创建tar.gz包
#!/usr/bin/env python
import os
import tarfile
#创建压缩包名
tar = tarfile.open("/tmp/tartest.tar.gz","w:gz")
#创建压缩包
for root,dir,files in os.walk("/tmp/tartest"):
for file in files:
fullpath = os.path.join(root,file)
tar.add(fullpath)
tar.close()
2.解压tar.gz包
#!/usr/bin/env python
import tarfile
tar = tarfile.open(“/tmp/tartest.tar.gz”)
names = tar.getnames()
for name in names:
tar.extract(name,path=”/tmp”)
- Python下使用tarfile模块来实现文件归档压缩与解压
- Python下使用tarfile模块来实现文件归档压缩与解压
- Python中使用tarfile压缩、解压tar归档文件示例
- Python中使用tarfile压缩、解压tar归档文件
- 使用python tarfile 模块在 Windows 平台正确解压 tar 文件
- python中的压缩、解压包tarfile
- python 8-3-1 使用tarfile可以实现文件的压缩打包
- python 8-3-1 使用tarfile可以实现文件的压缩打包
- python tarfile模块基本使用
- python_使用tarfile压缩及解压的方法
- linux下的文件归档与解压
- Python Gzip压缩与解压模块
- python tarfile模块
- python tarfile模块
- linux下的文件压缩与打包,compress,gzip,zcat,bzip2,bzcat,tar,find,tarfile,tarball
- linux下的文件压缩与打包---compress,gzip,zcat,bzip2,bzcat,tar,find,tarfile,tarball
- linux下的文件压缩与打包,compress,gzip,zcat,bzip2,bzcat,tar,find,tarfile,tarball
- Linux下使用gzip压缩与解压文件
- 用Python解压tgz文件
- 在Eclipse中使用JUnit4进行单元测试(实例篇)
- 马尔科夫随机场的基本概念
- 关于easyui中的样式应用
- 排序
- Python下使用tarfile模块来实现文件归档压缩与解压
- Single Number
- CSS居中
- python解压缩tar.gz文件
- 【设计模式】漫谈六大原则
- Android Studio系列教程一--下载与安装
- Javascript 获取键盘的KeyCode
- SQL数据库的语句整理
- Zindex和png