title: python os.rename(...) won't work !
body: <p>I am writing a Python function to change the extension of a list of files into another extension, like txt into rar, that's just an idle example. But I'm  getting an error. The code is:</p>
  
  <pre><code>import os
  def dTask():
      #Get a file name list
      file_list = os.listdir('C:\Users\B\Desktop\sil\sil2')
      #Change the extensions
      for file_name in file_list:
          entry_pos = 0;
          #Filter the file name first for '.'
          for position in range(0, len(file_name)):
              if file_name[position] == '.':
                  break
          new_file_name = file_name[0:position]
          #Filtering done !
          #Using the name filtered, add extension to that name
          new_file_name = new_file_name + '.rar'
          #rename the entry in the file list, using new file name
          print 'Expected change from: ', file_list[entry_pos]
          print 'into File name: ', new_file_name
          os.rename(file_list[entry_pos], new_file_name)
          ++entry_pos
  Error:
  &gt;&gt;&gt; dTask()
  Expected change from:  New Text Document (2).txt
  into File name:  New Text Document (2).rar
  Traceback (most recent call last):
    File "&lt;pyshell#10&gt;", line 1, in &lt;module&gt;
      dTask()
    File "C:\Users\B\Desktop\dTask.py", line 19, in dTask
      os.rename(file_list[entry_pos], new_file_name)
  WindowsError: [Error 2] The system cannot find the file specified
  </code></pre>
  
  <p>I can succeed in getting the file name with another extension in variable level as you can see in the print-out, but not in reality because I can not end this process in OS level. The error is coming from os.rename(...). Any idea how to fix this ? </p>