I wanted a function, possibly amongst Path Functions, that would check if file-name would be valid. By valid, I meant if character present in the string are all valid (having no ?
, >
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.
- Using a regular expression to check the contents of filename.
- Creating a file name, possibly in
%TEMP%
path of the system. If creation fails, the filename is (possibly) invalid. Otherwise, it is valid (and therefore, delete the file). - Write up a function, that checks if invalid characters are present in the filename (e.g.
?:*>
)
An extended form of function would be to check all invalid names (like AUX
, CON
etc), but that's not an issue (at least for now).
Is there any documented/undocumented function, that I might have missed, which would reliably check if filename (not pathname) is valid.