How do I check if a given string is a legal/valid file name under Windows?

后端 未结 27 1361
-上瘾入骨i
-上瘾入骨i 2020-11-22 09:38

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 n

27条回答
  •  盖世英雄少女心
    2020-11-22 10:13

    Windows filenames are pretty unrestrictive, so really it might not even be that much of an issue. The characters that are disallowed by Windows are:

    \ / : * ? " < > |
    

    You could easily write an expression to check if those characters are present. A better solution though would be to try and name the files as the user wants, and alert them when a filename doesn't stick.

提交回复
热议问题