Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing the files in a folder from JPG to JPEG

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')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading