Renaming files in python

I had downloaded 2012 id pics but couldn’t view them due to the following error . Error interpreting JPEG image file (Not a JPEG file: starts with 0x89 0x50)

On googling I found out that the image had to be renamed as a ‘.png file’ . But I couldnt do them manually as there are 700 odd id pics. Hope this helps.


import os

os.chdir('/home/manoj/Downloads/2012IDPics/')

idpics = os.listdir(os.getcwd())

for idpic in idpics:

os.rename(idpic , idpic[:-3] + 'png')

Hope that helps.

P.S: Going through highly disappointing times . Hoping for something substantial to work on.

One comment

  1. Unknown's avatar
    Anonymous · · Reply

    You really make it seem really easy with your presentation however I in finding this matter to be really one thing which I believe I might never understand. It sort of feels too complex and very vast for me. I am looking ahead to your next put up, I’ll try to get the hang of it!

Leave a comment

Design a site like this with WordPress.com
Get started