[Tutor] Removing a file from a tar

David Rock david at graniteweb.com
Wed Jun 27 22:38:14 CEST 2007


* Adam A. Zajac <strider1551 at gmail.com> [2007-06-27 11:26]:
> I was reading over the documentation for the tarfile module and it
> occurred to me that there didn't seem to be a way to remove an
> individual file from the tar.
> 
> For example, suppose I did this:
> 
> import tarfile
> tar = tarfile.open("sample.tar", "w")
> tar.add("unwanted")
> tar.add("wanted")
> tar.close()
> 
> At this point, how could I come back and remove "unwanted" from the tar?

Wel, it looks like tar's --remove-files is not supported yet, you would
probably have to reopen the tarfile, write it to a new one file-by-file,
excluding the ones you don't want.  Messy :-(

-- 
David Rock
david at graniteweb.com


More information about the Tutor mailing list