how should i add extension and unzip again?

PK Khatri piseema at gmail.com
Wed Mar 18 19:22:47 EDT 2015


This script untars .gz file to file without extension
--------
import gzip
import glob
import os.path
import tarfile

source_dir = "C:\\TEST"
dest_dir = "C:\\TEST"
for src_name in glob.glob(os.path.join(source_dir, '*.gz')):
    base = os.path.basename(src_name)
    dest_name = os.path.join(dest_dir, base[:-3])
    with tarfile.open(src_name, 'r') as infile:
        with open(dest_name, 'w') as outfile:
            for line in infile:
                outfile.write(str(line))
---------
 but i know it is a compressed file so I need to add extension .zip to it and run untar/unzip one more time so it will fully unzip to folders and files, not sure how, can someone help please?
Thank you.



More information about the Python-list mailing list