Skip to content

Instantly share code, notes, and snippets.

@whoo24
Created August 25, 2016 02:57
Show Gist options
  • Save whoo24/35b6cbb0603aef04b73b44f675aa67f8 to your computer and use it in GitHub Desktop.
Save whoo24/35b6cbb0603aef04b73b44f675aa67f8 to your computer and use it in GitHub Desktop.
import os
import fnmatch
prefix = "page-"
postfix = ".jpg"
add_num = 1;
digits = 3;
v = []
for filename in os.listdir("."):
if fnmatch.fnmatch(filename, prefix + "*" + postfix ):
v.append(filename)
v.reverse()
i = len(v)
format_string = '{0}{2:0' + str(digits) + 'd}{1}'
for filename in v:
newname = format_string.format(prefix, postfix, i)
print '{0} -> {1}'.format(filename, newname)
os.rename( filename, newname )
#print ()
i = i - 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment