Extracting a File from a TAR File : tar file « File « Python Tutorial






import os
import tarfile

extractPath = "/bin/py"

#Open Tar file
tFile = tarfile.open("files.tar", 'r')

#Extract py files in tar
for f in tFile.getnames():
    if f.endswith("py"):
        print "Extracting %s" % f
        tFile.extract(f, extractPath)
    else:
        print "%s is not a Python file." % f

tFile.close()








12.22.tar file
12.22.1.Creating a TAR File
12.22.2.Extracting a File from a TAR File