Windows 禁用文件和文件夹名称的完整列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4195347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Complete List of forbidden file and folder names for windows
提问by sdu
On Windows file names like com1.txt or lpt1.txt are forbidden. Is there a list of all forbidden file and folder names on windows (or forbidden chars in the file and folder names like :? ...)
在 Windows 上,禁止使用 com1.txt 或 lpt1.txt 等文件名。是否有 Windows 上所有禁用文件和文件夹名称的列表(或文件和文件夹名称中的禁用字符,如 :? ...)
回答by ChrisF
The list of invalid characters is:
无效字符列表是:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
- <(小于)
- >(大于)
- : (冒号)
- "(双引号)
- /(正斜杠)
- \(反斜杠)
- | (垂直条或管)
- ? (问号)
- *(星号)
Plus characters 1 to 31
加字符 1 到 31
But you should use System.IO.Path.GetInvalidFileNameChars
and System.IO.Path.GetInvalidPathChars
(or their equivalents) as recommended by FlipScript as a) it's neater and b) means that if the list ever changes you won't have to modify your application.
但是您应该按照 FlipScript 的建议使用System.IO.Path.GetInvalidFileNameChars
and System.IO.Path.GetInvalidPathChars
(或它们的等效项),因为 a) 它更整洁 b) 意味着如果列表发生变化,您将不必修改您的应用程序。
回答by Pacane
回答by Flipster
You didn't mention what platform you are using, but in .Net, you can use:
您没有提到您使用的是什么平台,但在 .Net 中,您可以使用:
System.IO.Path.GetInvalidFileNameChars
and
和
System.IO.Path.GetInvalidPathChars
To return invalid file name and path characters.
返回无效的文件名和路径字符。