pythonexceptiontarfile

Python tarfile module overwrites existing files during extraction - how to disable it?


Is there a way prevent tarfile.extractall (API) from overwriting existing files? By "prevent" I mean ideally raising an exception when an overwrite is about to happen. The current behavior is to silently overwrite the files.


Solution

  • You could check result of tarfile.getnames against the existing files and raise your error.