title: How to rename last letter but not the file ending in python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8314983/how-to-change-last-letter-of-filename-to-lowercase-if-it-is-a-letter">How to change last letter of filename to lowercase if it is a letter?</a>  </p>
  </blockquote>
  
  
  
  <p>This post is a follow-up of my previous post. 
  The Answer below was from Abhijit.</p>
  
  <p>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</p>
  
  <p>Rob</p>
  
  <pre><code>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()
  </code></pre>