python压缩和读取.tar.bz2格式的压缩包详解编程语言

python可以通过tarfile模块压缩和解压.tar.bz2包

#压缩文件夹为 .tar.bz2 
import tarfile 
import bz2 
archive = tarfile.open('myarchive.tar.bz2','w:bz2') 
archive.debug = 1           # Display the files beeing compressed. 
archive.add(r'd:/myfiles')  # d:/myfiles contains the files to compress 
archive.close() 
  
#解压一个.tar.bz2 
import tarfile 
import bz2 
archive = tarfile.open('myarchive.tar.bz2','r:bz2') 
archive.debug = 1    # Display the files beeing decompressed. 
for tarinfo in archive: 
    archive.extract(tarinfo, r'd:/mydirectory') # d:/mydirectory is where I want to uncompress the files. 
archive.close()

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8255.html

(0)
上一篇 2021年7月18日 19:30
下一篇 2021年7月18日 19:31

相关推荐

发表回复

登录后才能评论