title: WindowsError: [Error 2] The system cannot find the file specified, cannot resolve in Python
body: <p>I have made a Python program which will clean up the unnecessary names present in my downloaded torrent files+folders, so that I can upload it to my unlimited Google Drive Storage Account without much hassle.</p>
  
  <p>However, it gives me the: <code>WindowsError: [Error 2] The system cannot find the file specified</code> after certain number of iterations.<strong>If I run the program again, it works fine for a certain iterations and then the same error pops up.</strong></p>
  
  <p>Note that I have taken precautions using <code>os.path.join</code> to avoid this error but it keeps coming up. Because of this error, I have to run the program tens of times over a selected folder/drive.</p>
  
  <p>Here is my program: </p>
  
  <pre><code>import os
  terms = ("-LOL[ettv]" #Other terms removed
  )
  #print terms[0]
  p = "E:\TV Series"
  for (path,dir,files) in os.walk(p):
      for name in terms:
          for i in files:
              if name in i:
                  print i
                  fn,_,sn = i.rpartition(name)
                  os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
          for i in dir:
              if name in i:
                  print i
                  fn,_,sn = i.rpartition(name)
                  os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
  </code></pre>
  
  <p>And the Error Traceback:</p>
  
  <pre><code>Traceback (most recent call last):
  File "E:\abcd.py", line 22, in &lt;module&gt;
  os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
  WindowsError: [Error 2] The system cannot find the file specified
  </code></pre>