Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 13
    +1 for including reserved filenames - those were missed in previous answers. Commented Apr 20, 2009 at 14:41
  • 2
    "AUX" is a perfectly usable filename if you use the "\\?\" syntax. Of course, programs that don't use that syntax have real problems dealing with it... (Tested on XP) Commented Dec 2, 2009 at 13:19
  • 15
    The correct regex for all these conditions mentioned above is as below:Regex unspupportedRegex = new Regex("(^(PRN|AUX|NUL|CON|COM[1-9]|LPT[1-9]|(\\.+)$)(\\..*)?$)|(([\\x00-\\x1f\\\\?*:\";|/<>])+)|(([\\. ]+)", RegexOptions.IgnoreCase); Commented Feb 19, 2015 at 5:58
  • 6
    @whywhywhy I think you've got an extra opening bracket in that Regex. "(^(PRN|AUX|NUL|CON|COM[1-9]|LPT[1-9]|(\\.+)$)(\\..*)?$)|(([\\x00-\\x1f\\\\?*:\";‌​|/<>])+)|([\\. ]+)" worked for me. Commented Aug 20, 2015 at 21:00
  • 8
    I read the same article mentioned in this answer and found through experimentation that COM0 and LPT0 are also not allowed. @dlf this one works with filenames that begin with '.': ^(?!^(?:PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d)(?:\..+)?$)(?:\.*?(?!\.))[^\x00-\x1f\\?*:\";|\/<>]+(?<![\s.])$ Commented May 14, 2016 at 16:43