title: Save file and rename old version
body: <p>I have pickled (dumped) my model and saved it for use in a web application. Each time I re-run analysis of the model, the file is pickled again and saved in the same folder under the (file name + date). In case the new file is created on the same day as the last version I would like to rename the old version.</p>
  
  <p>I attempted to rename the old file by adding <code>'_archived'</code> to the end. The code below correctly creates a new file when none exists but when file already exists re-running it removes old file and throws error.  </p>
  
  <pre><code>path = r'C:\scoring_model'
  dest = os.path.join(path, 'test12')
  
  now = pd.datetime.now()
  date_now = str(now.date())    
  model_name = 'model' + '_' + date_now
  model_loc = os.path.join(dest, model_name)
  
  if os.path.exists(model_loc):    
      try:
          os.rename(model_loc, model_name + '_archived')
  
      except:
          os.remove(model_loc)
          os.rename(model_loc, model_name + '_archived')
          with open(model_loc, 'wb') as pfile:
              pickle.dump(scoring_model, pfile)
  
  else:
      with open(model_loc, 'wb') as pfile:
          pickle.dump(scoring_model, pfile)
  </code></pre>
  
  <p>I get the following error:  </p>
  
  <pre><code>WindowsError                              Traceback (most recent call last)
  &lt;ipython-input-186-c132203d92f3&gt; in &lt;module&gt;()
       16     except:
       17         os.remove(model_loc)
  ---&gt; 18         os.rename(model_loc, model_name + '_archived')
       19         with open(model_loc, 'wb') as pfile:
       20             pickle.dump(scoring_model, pfile)
  
  WindowsError: [Error 2] The system cannot find the given file
  </code></pre>