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.

Advertisements

One comment

  1. 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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: