Skip to content

Instantly share code, notes, and snippets.

@sambao21
Created November 3, 2012 07:42
Show Gist options
  • Save sambao21/4006459 to your computer and use it in GitHub Desktop.
Save sambao21/4006459 to your computer and use it in GitHub Desktop.
rename files for transfer to ipad
import os
upDir = '/Users/sambao21'
rootDir = '{0}/ipad_pics'.format(upDir)
y = 100
for dirName,subdirList,fileList in os.walk( rootDir ) :
print "Found directory:" , dirName
x = 0
for fname in fileList:
path = dirName + '/'
if 'jpg' in fname.lower():
new_fname = "IMG_%.4d.jpg" % x
print "* {0}{1} -> {0}{2}".format(path, fname, new_fname)
os.rename('{0}{1}'.format(path,fname), '{0}{1}'.format(path,new_fname))
x += 1
else:
print '- {0}{1}'.format(path, fname)
os.remove('{0}{1}'.format(path, fname))
if dirName != rootDir:
newdir = 'CANON%.3d' % y
newpath = '{0}/{1}'.format(rootDir, newdir)
print '### {0} -> {1}'.format(dirName, newpath)
os.rename(dirName, newpath)
y += 1
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment