各种平台保留的文件名是什么?

时间:2020-03-06 14:36:45  来源:igfitidea点击:

我不是在问文件名的一般语法规则。我的意思是,陷阱突然冒出来咬你。例如,尝试在Windows上命名文件" COM <n>"?

解决方案

好吧,对于MSDOS / Windows,NUL,PRN,LPT <n>和CON。如果与扩展名一起使用,它们甚至会引起问题:" NUL.TXT"

不知道时会遇到棘手的Unix陷阱:

以或者-开头的文件是合法的,但使用起来很麻烦,因为许多命令行工具都认为我们正在为它们提供选项。

这些工具中的许多工具都有一个特殊的标记"-"来表示选项的结束:

gzip -9vf -- -mydashedfilename

除非我们要触摸特殊目录,否则Linux上唯一的非法名称是"."和".."。可以使用任何其他名称,尽管从外壳程序访问其中的某些名称需要使用转义序列。

编辑:正如Vinko Vrsalovic所说,以'-'和'--`'开头的文件是shell的麻烦,因为那些字符序列是由应用程序而不是shell解释的。

来源:http://www.grouplogic.com/knowledge/index.cfm/fuseaction/view_Info/docID/111.

The following characters are invalid as file or folder names on Windows  using NTFS: / ? < > \ : * | " and any character you can type with the Ctrl key.
  
  In addition to the above illegal characters the caret ^ is also not permitted under Windows Operating Systems using the FAT file system.
  
  Under Windows using the FAT file system file and folder names may be up to 255 characters long.
  
  Under Windows using the NTFS file system file and folder names may be up to 256 characters long.
  
  Under Window the length of a full path under both systems is 260 characters.
  
  In addition to these characters, the following conventions are also illegal:
  
  
  Placing a space at the end of the name
  Placing a period at the end of the name
  
  
  The following file names are also reserved under Windows:
  
  
  com1,
  com2,
  ...
  com9,
  lpt1,
  lpt2,
  ...
  lpt9,
  con,
  nul,
  prn

Windows上合法和非法文件名的完整说明:http://msdn.microsoft.com/zh-cn/library/aa365247.aspx

boost :: filesystem可移植性指南提供了很多很好的信息。