title: Windows filename - How to check if filename would be valid?
body: <p>I wanted a function, possibly amongst <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb773559(v=vs.85).aspx" rel="nofollow noreferrer">Path Functions</a>, that would check if file-name would be valid. By valid, I meant if character present in the string are all valid (having no <code>?</code>, <code>&gt;</code> etc, for example). But sadly, there is no function. Browsing through the net, and SO, I found few techniques, none of them I liked, or found solid.</p>
  
  <ul>
  <li>Using a regular expression to check the contents of filename.</li>
  <li>Creating a file name, possibly in <code>%TEMP%</code> path of the system. If creation fails, the filename is (<em>possibly</em>) invalid. Otherwise, it is valid (and therefore, delete the file).</li>
  <li>Write up a function, that checks if invalid characters are present in the filename (e.g. <code>?:*&gt;</code>)</li>
  </ul>
  
  <p>An extended form of function would be to check all invalid names (like <code>AUX</code>, <code>CON</code> etc), but that's not an issue (at least for now).</p>
  
  <p>Is there any documented/undocumented function, that I might have missed, which would reliably check if filename (<strong>not</strong> pathname) is valid.</p>