Python tarfile

From wikinotes
Revision as of 21:59, 30 August 2016 by Will (talk | contribs) (→‎append)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

read

import tarfile

with tarfile.open( '/home/will/file.tar', 'r' ) as archive:
	contents = archive.getnames()

append

import tarfile

with tarfile.open( '/home/will/file.tar', 'a' ) as archive:
	for filepath in newfiles:
		archive.add( filepath, arcname=os.path.basename(filepath) )