Possible Duplicate:
How to change last letter of filename to lowercase if it is a letter?
This post is a follow-up of my previous post. The Answer below was from Abhijit.
It checks the last character of a filename and changes it to lower case if it is a character. I need to adapt it so that it checks the 5th from last character instead. e.g fooB.PNG > foob.PNG
Rob
import fnmatch
import os
def listFiles(dir):
rootdir = dir
for root, subFolders, files in os.walk(rootdir):
for file in files:
yield os.path.join(root,file)
return
for f in listFiles(r"N:\test1"):
if f[-5].isalpha():
os.rename(f,f[:-5]+f[-5].lower())
print "Renamed " + f + "to" + f[:-5]+f[-1].lower()