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