Check if a string is a valid Windows directory (folder) path

前端 未结 8 2076
说谎
说谎 2020-12-04 08:26

I am trying to determine whether a string input by a user is valid for representing a path to a folder. By valid, I mean formatted properly.

In my application, the f

8条回答
  •  暖寄归人
    2020-12-04 09:16

    Use this Code

    string DirectoryName = "Sample Name For Directory Or File";
    Path.GetInvalidFileNameChars()
      .Where(x => DirectoryName.Contains(x))
      .Count() > 0 || DirectoryName == "con"
    

提交回复
热议问题