2014/03/03

Python 3.3 透過Tarfile解壓縮

以bz2格式做示範

import tarfile

path = "/Users/cy/Desktop/Python/PDF.tar.bz2"
myFile = tarfile.open(path, "r:bz2")
members = myFile.getmembers()

for f in members:
    print("File name:{0}, mode:{1}".format(f.name, f.mode))

print("解壓縮")
myFile.extractall(members=members)
myFile.close()

解壓縮前

解壓縮後


參考資料:
http://docs.python.org/3/library/tarfile.html#module-tarfile
http://docs.python.org/3/library/tarfile.html#tarfile.TarInfo