Directory.GetFiles finds nonexisting files

后端 未结 3 570
無奈伤痛
無奈伤痛 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条回答
  •  无人及你
    2021-02-07 04:46

    These are reserved words by MSDOS/NTFS.

    From Wikipedia:

    In addition, in Windows and DOS utilities, some words might also be reserved and can not be used as filenames. For example, DOS device files:

    CON, PRN, AUX, CLOCK$, NUL
    COM0, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
    LPT0, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.
    

    Systems that have these restrictions cause incompatibilities with some other filesystems. For example, Windows will fail to handle, or raise error reports for, these legal UNIX filenames: aux.c, q"uote"s.txt, or NUL.txt.

    NTFS filenames that are used internally include:

    $Mft, $MftMirr, $LogFile, $Volume, $AttrDef, $Bitmap, $Boot, $BadClus, $Secure,
    $Upcase, $Extend, $Quota, $ObjId and $Reparse
    

提交回复
热议问题