Python3 脚本 解压缩文件夹中的所有gz文件

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)
原文地址:https://www.cnblogs.com/liujx2019/p/14077759.html