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)

 

posted on 2020-12-03 09:35  liujx2019  阅读(1236)  评论(0编辑  收藏  举报

导航