How can I validate if a file is name valid in Windows?

前端 未结 3 1473
囚心锁ツ
囚心锁ツ 2021-02-20 11:23

Is there a Windows API function that I can pass a string value to that will return a value indicating whether a file name is valid or not?

I need to verify that a file n

3条回答
  •  爱一瞬间的悲伤
    2021-02-20 11:45

    In case you are checking if the file name is valid in the sense "can the file be named like this?" :

    No, there is no function to directly check that. You will have to write you own function.

    But, if you know what is a valid file name (the valid file name does now contain any of the following: \ / : * ? " < > |) that shouldn't be such a problem.

    You could perhaps help your self with some of these functions from ctype.h (with them you can check if a specific character belongs to some specific character classes):

    http://www.cplusplus.com/reference/clibrary/cctype/

提交回复
热议问题