title: I would like to copy a file to a new directory and then rename it using the datetime :: Python
body: <p>So my title says it, but looking around for help on the move and then renaming it with the datetime hasn't proven as simple as I had hoped. Here is the code so far:</p>
  
  <pre><code>import os
  import shutil
  import time
  timestr = time.strftime("%Y%m%d-%H%M%S")
  
  srcfile = '/Users/foo/bar/log.html'
  dstroot = '/Users/foo/bar/newlogs/'
  
  
  assert not os.path.isabs(log.html)
  dstdir =  os.path.join(dstroot, os.path.dirname(log.html))
  shutil.copy(log.html, dstdir)
  
  os.rename ('log.html', timestr.'lognew.html')
  </code></pre>