Python: View what file is currently being extracted from a tar file

As part of a Python script, you are extracting a tar file. But you want to output the name of each file in the tar as it is being extracted (for logging, etc). How to do this?

Below is a code snippet that worked well for me:

getmembers() returns the members of the archive as a list of TarInfo objects.
You can then simply print the .name of each member, before then extracting that file.

Therefore, if your extract failed for any reason, this allows your logs to show which file the extract failed on.

This entry was posted in Design/Dev and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*