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

后端 未结 27 1725
-上瘾入骨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:21

    The question is are you trying to determine if a path name is a legal windows path, or if it's legal on the system where the code is running.? I think the latter is more important, so personally, I'd probably decompose the full path and try to use _mkdir to create the directory the file belongs in, then try to create the file.

    This way you know not only if the path contains only valid windows characters, but if it actually represents a path that can be written by this process.

提交回复
热议问题