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?
I want to include a batch file rename functionality in my application. A user
Share
You can get a list of invalid characters from
Path.GetInvalidPathCharsandGetInvalidFileNameChars.UPD: See Steve Cooper’s suggestion on how to use these in a regular expression.
UPD2: Note that according to the Remarks section in MSDN ‘The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names.’ The answer provided by sixlettervaliables goes into more details.