title: Accessing Dynamically-Named Directory in Python
body: <p>I'm currently putting together a script in Python which will do the following:-</p>
  
  <ul>
  <li>Create a directory in my Dropbox folder called 'Spartacus'</li>
  <li>Create a subdirectory in this location with the naming convention of the date and time of creation</li>
  <li>Within this directory, create a file called iprecord.txt and information will then be written to this file.</li>
  </ul>
  
  <p>Here is my code thusfar using Python v2.7 on Windows 7:-</p>
  
  <pre><code>import os
  import time
  import platform
  import urllib
  
  current_dir = os.getcwd()
  targetname = "Spartacus"
  target_dir = os.path.join(current_dir, targetname)
  timenow = time.strftime("\%d-%b-%Y %H-%M-%S")
  
  def directoryVerification():
      os.chdir(current_dir)
      try:
          os.mkdir('Spartacus')
      except OSError:
          pass
      try:
          os.system('attrib +h Spartacus')
      except OSError:
          pass
  
  def gatherEvidence():
      os.chdir(target_dir)
      try:
          evidential_dir = os.mkdir(target_dir + timenow)
          os.chdir(evidential_dir)
      except OSError:
          pass
      f = iprecord.txt
      with f as open:
          ip_addr = urllib.urlopen('http://www.biranchi.com/ip.php').read()
          f.write("IP Address:\t %s\t %s" % ip_addr, time.strftime("\%d-%b-%Y %H-%M-%S"))
  
  
  x = directoryVerification()
  y = gatherEvidence()
  </code></pre>
  
  <p>I keep on getting an error in line 26 whereby it cannot resolve the full path to the dynamically named directory (date and time) one. I've printed out the value of 'evidential_dir' and it shows as being Null.</p>
  
  <p>Any pointers as to where I am going wrong? Thanks</p>
  
  <p>PS: Any other advice on my code to improve it would be appreciated
  PPS: Any advice on how to locate the default directory for 'Dropbox'? Is there a way of scanning a file system for a directory called 'Dropbox' and capturing the path?</p>