title: How to copy an image from server directory to another directory in python
body: <p>I am trying to copy an image from a directory on my server and paste is to another file on server. Then I am looking to rename it.</p>
  
  <p>Here is my code (New to python)</p>
  
  <pre><code>#! /usr/bin/python
  import cgi
  import os
  import shutil
  
  print "Content-type: text/html\r\n\r\n"
  username = 'bytesized'
  srcfile = 'http://test.com/img/default/basicprof.jpg'
  dstroot = 'http://test.com/img/%s.jpg' % username 
  
  assert not os.path.isabs(srcfile)
  dstdir =  os.path.join(dstroot, os.path.dirname(srcfile))
  
  os.makedirs(dstdir)
  shutil.copy(srcfile, dstdir)
  </code></pre>