title: Directory names are not changed in for loop
body: <p>I'm trying to recursively rename all subdirectories and files in a directory, specifically to get rid of German umlaut and replace them with their "safe" counterparts (i.e. replacing 'ü' with 'ue').</p>
  
  <p>For the renaming, I found the following code</p>
  
  <pre><code>def remove_umlaut(string):
      """
      Removes umlauts from strings and replaces them with the letter+e convention
      :param string: string to remove umlauts from
      :return: unumlauted string
      """
      u = 'ü'.encode()
      U = 'Ü'.encode()
      a = 'ä'.encode()
      A = 'Ä'.encode()
      o = 'ö'.encode()
      O = 'Ö'.encode()
      string = string.encode()
      string = string.replace(u, b'ue')
      string = string.replace(U, b'Ue')
      string = string.replace(a, b'ae')
      string = string.replace(A, b'Ae')
      string = string.replace(o, b'oe')
      string = string.replace(O, b'Oe')
      string = string.decode('utf-8')
      return string
  </code></pre>
  
  <p>And that works when tested alone. My recursive renaming function looks like this:</p>
  
  <pre><code>def renameInvalid(root):
      for f in os.listdir():
          old = f 
          f = remove_umlaut(f)
          if old != f:                              
              os.rename(old,f)                
              print("renamed " + old + " to " + f )
          if os.path.isdir(f):
              os.chdir(f)
              renameInvalid(".")
              os.chdir("..")  
  </code></pre>
  
  <p>When I test this in an interpreter, the issue seems to be that when iterating through os.listdir(), the strings cannot be changed. Neither with above funciton nor with regex.</p>
  
  <p>Tested this on Mac and Windows.</p>
  
  <p>Where is the mistake?</p>