title: Scan directory and rename files in Python
body: <p>I have 7 files in my <strong>web</strong> directory like this : </p>
  
  <p><a href="https://i.stack.imgur.com/CdInc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CdInc.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to scan through all my files in that folder and rename a certain files. </p>
  
  <p>I have </p>
  
  <pre><code>import os
  
  path = '/Users/username/Desktop/web'
  for filename in os.listdir(path):
      if filename.startswith("test"):
          print 'found'
          os.rename(filename, filename.replace("test_", " "))
      else:
          continue
  </code></pre>
  
  <p>After run it, </p>
  
  <p><strong>python scan_dir.py</strong></p>
  
  <p>I got </p>
  
  <pre><code>found
  Traceback (most recent call last):
    File "scan_dir.py", line 9, in &lt;module&gt;
      os.rename(filename, filename.replace("test_", " "))
  OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>Any hints on what I did wrong ? </p>