title: Check whether a path is valid in Python without creating a file at the path's target
body: <p>I have a path (including directory and file name).<br>
  I need to test if the file-name is a valid, e.g. if the file-system will allow me to create a file with such a name.<br>
  The file-name <em>has some unicode characters</em> in it.</p>
  
  <p>It's safe to assume the directory segment of the path is valid and accessible (<sup>I was trying to make the question more gnerally applicable, and apparently I wen too far</sup>).</p>
  
  <p>I very much do not want to have to escape anything unless I <em>have</em> to. </p>
  
  <p>I'd post some of the example characters I am dealing with, but apparently they get automatically removed by the stack-exchange system. Anyways, I want to keep standard unicode entities like <code>ö</code>, and only escape things which are invalid in a filename.</p>
  
  <hr>
  
  <p>Here is the catch. <strong>There may (or may not) already be a file at the target of the path.</strong> I need to keep that file if it does exist, and not create a file if it does not.</p>
  
  <p>Basically I want to check if I <em>could</em> write to a path <strong>without actually opening the path for writing</strong> (and the automatic file creation/file clobbering that typically entails).</p>
  
  <p>As such:</p>
  
  <pre><code>try:
      open(filename, 'w')
  except OSError:
      # handle error here
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/4102896/check-whether-a-path-is-valid-in-python">from here</a></p>
  
  <p>Is not acceptable, because it will overwrite the existent file, which I do not want to touch (if it's there), or create said file if it's not.</p>
  
  <p>I know I can do:</p>
  
  <pre><code>if not os.access(filePath, os.W_OK):
      try:
          open(filePath, 'w').close()
          os.unlink(filePath)
      except OSError:
          # handle error here
  </code></pre>
  
  <p>But that will <em>create</em> the file at the <code>filePath</code>, which I would then have to <code>os.unlink</code>.</p>
  
  <p>In the end, it seems like it's spending 6 or 7 lines to do something that should be as simple as <code>os.isvalidpath(filePath)</code> or similar.</p>
  
  <hr>
  
  <p>As an aside, I need this to run on (at least) Windows and MacOS, so I'd like to avoid platform-specific stuff.</p>
  
  <p>``</p>