Search code examples
pythontarfile

Extracting file from tarfile with only basename using Python


I have a 'tafile' which contains files with complete path '/home/usr/path/to/file'. When I extract the file to the curent folder it creates the complete path recursively. Is there a way that I can extract the file with only the base name.


Solution

  • Use TarFile.extractfile() and write it into a file of your choice.