How to unpack .tar.gz files with Python?

Discussion created by BrunodeDeus on Jan 30, 2017
Latest reply on Jan 30, 2017 by BrunodeDeus
Branched from an earlier discussion

I would like do the same thing to multiple Giz and Tarfiles. I already replaced "zipfile" for "tarfile" at the script, but It doesn't works with Python 2.7.1 at ArcMap 10.1 (but will be good which It works with newer ArcMap)


>>> import tarfile,fnmatch,os
... rootPath = r"C:\Teste_Auto_Unzip"
... pattern = '*.tar.gz'
... for root, dirs, files in os.walk(rootPath):
...     for filename in fnmatch.filter(files, pattern):
...         print(os.path.join(root, filename))
...         tarfile.TarFile(os.path.join(root, filename)).extractall(
                os.path.join(root, filename.split(".")[0]))
Runtime error
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\ArcGIS10.4\Lib\", line 1581, in __init__
self.firstmember =
File "C:\Python27\ArcGIS10.4\Lib\", line 2356, in next
raise ReadError(str(e))
ReadError: invalid header



Thanks in advance!