Python: Use tarfile to delete files from the TAR archive … here is a solution to the problem.
Python: Use tarfile to delete files from the TAR archive
Is it possible to use tarfile
to delete some files from the TAR archive?
For example:
If the x.tar
file contains files A.txt, B
.txt, and C
.txt, can I delete A.txt
?
In other words: is there any Python solution to achieve something like this:
tar -vf x.tar --delete a.txt
?
Solution
Instead of using tarfiles
directly, although there may be some other libraries out there. A quick crack you can do is to extract the file and then recreate the tar
minus the file you want to delete.