BrunodeDeus

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

Hi,
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]))
...
C:\Teste_Auto_Unzip\LC82270692015242LGN00.tar.gz
Runtime error
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\ArcGIS10.4\Lib\tarfile.py", line 1581, in __init__
self.firstmember = self.next()
File "C:\Python27\ArcGIS10.4\Lib\tarfile.py", line 2356, in next
raise ReadError(str(e))
ReadError: invalid header

 

 

Thanks in advance!

Outcomes