Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import os, sys, imghdr
if len(sys.argv) == 2:
except OSError, e:
if e.errno == 2:
print "No such file or directory: '%s'" % sys.argv[1]
for i in os.listdir('.'):
if os.path.isfile(i):
name = i
while os.path.splitext(os.path.splitext(name)[0])[1] != '':
name = os.path.splitext(name)[0]
fmt = imghdr.what(i)
xname = os.path.splitext(name)[1][1:].lower()
if fmt != None and fmt != xname:
if fmt == 'jpeg' and xname == 'jpg':
cn = os.path.splitext(name)[0] + '.' + fmt
os.rename(i, cn)
print 'Renamed %s to %s' % (i, cn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.