[Python] python压缩和读取.tar.bz2格式的压缩包 →→→→→进入此内容的聊天室

来自 , 2019-05-14, 写在 Python, 查看 109 次.
URL http://www.code666.cn/view/4aeae10e
  1. #压缩文件夹为 .tar.bz2
  2. import tarfile
  3. import bz2
  4. archive = tarfile.open('myarchive.tar.bz2','w:bz2')
  5. archive.debug = 1           # Display the files beeing compressed.
  6. archive.add(r'd:\myfiles')  # d:\myfiles contains the files to compress
  7. archive.close()
  8.  
  9. #解压一个.tar.bz2
  10. import tarfile
  11. import bz2
  12. archive = tarfile.open('myarchive.tar.bz2','r:bz2')
  13. archive.debug = 1    # Display the files beeing decompressed.
  14. for tarinfo in archive:
  15.     archive.extract(tarinfo, r'd:\mydirectory') # d:\mydirectory is where I want to uncompress the files.
  16. archive.close()
  17. #//python/234

回复 "python压缩和读取.tar.bz2格式的压缩包"

这儿你可以回复上面这条便签

captcha