I want to include a batch file rename functionality in my application. A user can type a destination filename pattern and (after replacing some wildcards in the pattern) I need to check if it's going to be a legal filename under Windows. I've tried to use regular expression like [a-zA-Z0-9_]+
but it doesn't include many national-specific characters from various languages (e.g. umlauts and so on). What is the best way to do such a check?
From MSDN's "Naming a File or Directory," here are the general conventions for what a legal file name is under Windows:
You may use any character in the current code page (Unicode/ANSI above 127), except:
<
>
:
"
/
\
|
?
*
Some optional things to check:
\?\
prefix)\?\
(note that prefix may expand directory components and cause it to overflow the 32,000 limit)