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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM