title: Check if directory has read/write permissions
body: <p>My environment is <em>Python 3.7.2</em>, running on <em>Windows 10</em>. </p>
  
  <p>I am working on some downloader. First of all I want to check if <strong>directory</strong> where I want to download files has <em>read / write</em> permissions:</p>
  
  <p>I tried two ways:</p>
  
  <p>1 code:</p>
  
  <p>Using os module (os.access function) to check access, returns True even if I have no write access. Module gives wrong results on Windows:</p>
  
  <pre><code># check for read/write access
  if not os.access(path, os.W_OK):
      raise PermissionError("Path %s, doesn't have WRITE permissions" % path)
  # check for write access
  if not os.access(path, os.R_OK):
       raise PermissionError("Path %s, doesn't have READ permissions" % path)
  </code></pre>
  
  <p>2 code:</p>
  
  <p>The idea to use <code>tempfile.TemporaryFile()</code> seemed clean way to check directory permission, with no risk of leaving junk files on the system. The problem is, tempfile.TemporaryFile() hangs on my system when it's given a <em>dir parameter that hasnt any permissions</em>,script won't continue to execute or exit. nothing is returned. it's just stuck at that line . The bug affects only Windows environments, but unfortunately it has the result of rendering tempfile.TemporaryFile unusable on Windows for this common use case:</p>
  
  <pre><code>import tempfile
  import errno
  
  try:
      testfile = tempfile.TemporaryFile(dir = path)
      testfile.close()
  except (OSError, IOError) as e:
      if e.errno == errno.EACCES or e.errno == errno.EEXIST:
          raise PermissionError("Path %s, doesn't have READ/WRITE permissions" % path)
  </code></pre>
  
  <p>Anyone has idea how to <strong>check permissions of a directory</strong>?</p>