Directory.GetFiles finds nonexisting files

后端 未结 3 616
無奈伤痛
無奈伤痛 2021-02-07 04:27

I just stumbled upon an undocumented behavior of the GetFiles methods in System.IO.Directory.

Whenever the searchPattern parameter

3条回答
  •  旧时难觅i
    2021-02-07 04:50

    This is known. It is an operating system design regarding Naming Files, Paths, and Namespaces (Windows)

    Excerpt:

    Do not use the following reserved names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended. For more information, see Namespaces.

    These are basically filename aliases (namespaces), so they always exist globally (in every folder). If you attempt to enumerate them, you'll get them back because they do exist.

提交回复
热议问题