Mode Description r Opens a TAR file for reading. r: Opens a TAR file for reading with no compression. w or w: Opens a TAR file for writing with no compression. a or a: Opens a TAR file for appending with no compression. r:gz Opens a TAR file for reading with gzip compression. w:gz Opens a TAR file for writing with gzip compression. r:bz2 Opens a TAR file for reading with bzip2 compression. w:bz2 Opens a TAR file for writing with bzip2 compression.
import os import tarfile
#Create Tar file tFile = tarfile.open("files.tar", 'w')
files = os.listdir(".") for f in files: tFile.add(f)
#List files in tar for f in tFile.getnames(): print "Added %s" % f
tFile.close()
Related Scripts with Example Source Code in same category :