您的当前位置:首页正文

快速转换文件夹下JPG文件为jpg(后缀置换即可)python

2024-11-29 来源:个人技术集锦

纯粹自己记录下来怕脚本玩丢了,很简单的脚本,没考虑png格式,需要的出门别的博客看去

import cv2 as cv
import os
dir_path = '/mnt/data-ractified/all/ground-truth/results'
file_list = os.listdir(dir_path)
for file in file_list:
    if not file.endswith('.jpg'):
        print('start changing! ' + file)
        ori_path = dir_path + '/' + file
        cv_file = cv.imread(ori_path)
        name,ext = file.split('.')
        des_path = dir_path + '/' + name + '.jpg'
        cv.imwrite(des_path,cv_file)
        print('finished! '+file)
        os.remove(ori_path)

显示全文