Monday, 23 January 2017

Extract files or unzip the tar files - python


import tarfile

# tar file to extract

theTarFile = 'D:\gcs task 1\suvi.gz'
# tar file path to extract

extractTarPath = 'D:\gcs task 1'
# open the tar filetfile = tarfile.open(theTarFile)
if tarfile.is_tarfile(theTarFile):
    # list all contents    print "tar file contents:"    print tfile.list(verbose=False)
    # extract all contents    tfile.extractall(extractTarPath)else:
    print theTarFile + " is not a tarfile."

No comments:

Post a Comment