How can I permanently change the files in a folder from JPG to JPEG using a script.
Here is my code, but it’s not producing any results:
for file in os.listdir(path):
if file.endswith(".JPG"):
base = os.path.splitext(file)[0]
os.rename(file, base + '.jpeg')
>Solution :
you can using opencv for this task:
(Note: in this code you must set ‘/’ at the end of path variable)
import os
import cv2
path = "./images/"
for file in os.listdir(path):
if file.endswith(".jpg") or file.endswith(".JPG"):
img = cv2.imread(path+str(file))
cv2.imwrite(path+file[0:-4]+".jpeg", img)
os.remove(path+file)