title: python: why does os.makedirs cause WindowsError?
body: <p>In python, I have made a function to make a directory if does not already exist. </p>
  
  <pre><code>def make_directory_if_not_exists(path):
      try:
          os.makedirs(path)
          break    
      except OSError as exception:
          if exception.errno != errno.EEXIST:
              raise
  </code></pre>
  
  <p>On Windows, sometimes I will get the following exception:</p>
  
  <p><code>WindowsError: [Error 5] Access is denied: 'C:\\...\\my_path'</code></p>
  
  <p>It seems to happen when the directory is open in the Windows File Browser, but I can't reliably reproduce it. So instead I just made the following workaround.</p>
  
  <pre><code>def make_directory_if_not_exists(path):
      while not os.path.isdir(path):
          try:
              os.makedirs(path)
              break    
          except OSError as exception:
              if exception.errno != errno.EEXIST:
                  raise
          except WindowsError:
              print "got WindowsError"
              pass       
  </code></pre>
  
  <p>What's going on here, i.e. when does Windows <code>mkdir</code> give such an access error? Is there a better solution?</p>