Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import os
  2.  
  3. # Create a list of files from the current directory who's last 4 characters
  4. # as lowercase are either '.jpg' or '.png'
  5.  
  6. files = [ f for f in os.listdir('.') if f[-4:].lower() in ('.jpg','.png') ]
  7.  
  8. DRYRUN = False
  9.  
  10. for (index,filename) in enumerate(files):
  11. extension = os.path.splitext(filename)[1]
  12. newname = "facebook-michael-%05d%s" % (index,extension)
  13. if os.path.exists(newname):
  14. print "Cannot rename %s to %s, already exists" % (filename,newname)
  15. continue
  16. if DRYRUN:
  17. print "Would rename %s to %s" % (filename,newname)
  18. else:
  19. print "Renaming %s to %s" % (filename,newname)
  20. os.rename(filename,newname)
Add Comment
Please, Sign In to add comment