且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Windows 下检查给定的字符串是否是合法/有效的文件名?

更新时间:2023-02-23 18:28:19

您可以从 Path.GetInvalidPathCharsGetInvalidFileNameChars.

UPD: 参见 Steve Cooper 关于如何在正则表达式中使用这些的建议.

UPD2: 请注意,根据 MSDN 中的备注部分不保证从此方法返回的数组包含在文件和目录名称中无效的完整字符集."提供的答案Sixlettervaliables 介绍了更多细节.

UPD2: Note that according to the Remarks section in MSDN "The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names." The answer provided by sixlettervaliables goes into more details.