Re: deleting from tarfile
Mark McEahern wrote: It doesn't appear so. A workaround, of course, is to create a new file with the subset of files from the old file: That is actually the *only* way to do that. tarfiles cannot be sparse, in the sense that parts of the file can be marked as deleted. So in order to delete a file, you have to copy the entire tarfile, and skip the file you want to delete - whether you do this yourself, or whether tarfile.py does it for you. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: deleting from tarfile
Uwe Mayer wrote: Hi, is it possible to delete a file from a tar-archive using the tarfile module? Thanks Uwe It doesn't appear so. A workaround, of course, is to create a new file with the subset of files from the old file: #!/usr/bin/env python import tarfile import os def removeFile(filename, nameToDelete): Remove nameToDelete from tarfile filename. prefix, ext = os.path.splitext(filename) newFilename = '%(prefix)s-modified%(ext)s' % locals() original = tarfile.open(filename) modified = tarfile.open(newFilename, 'w') for info in original.getmembers(): if info.name == nameToDelete: continue extracted = original.extractfile(info) if not extracted: continue modified.addfile(info, extracted) original.close() modified.close() // m -- http://mail.python.org/mailman/listinfo/python-list