import gzip import shutil def gunzip_shutil(source_filepath, dest_filepath, block_size=65536): with gzip.open(source_filepath, 'rb') as s_file, \ open(dest_filepath, 'wb') as d_file: shutil.copyfileobj(s_file, d_file, block_size) def loop_dir(path): files = os.listdir(path) for file in files: if not file.endswith('.gz'): continue gunzip_shutil(file, file[:-3]) def main(argv): loop_dir(argv[1]) if __name__ == '__main__': main(sys.argv)