What characters are forbidden in Windows and Linux directory names?

前端 未结 17 2842
北海茫月
北海茫月 2020-11-22 01:05

I know that / is illegal in Linux, and the following are illegal in Windows (I think) * . \" / \\ [

17条回答
  •  滥情空心
    2020-11-22 02:05

    Let's keep it simple and answer the question, first.

    1. The forbidden printable ASCII characters are:

      • Linux/Unix:

        / (forward slash)
        
      • Windows:

        < (less than)
        > (greater than)
        : (colon - sometimes works, but is actually NTFS Alternate Data Streams)
        " (double quote)
        / (forward slash)
        \ (backslash)
        | (vertical bar or pipe)
        ? (question mark)
        * (asterisk)
        
    2. Non-printable characters

      If your data comes from a source that would permit non-printable characters then there is more to check for.

      • Linux/Unix:

        0 (NULL byte)
        
      • Windows:

        0-31 (ASCII control characters)
        

      Note: While it is legal under Linux/Unix file systems to create files with control characters in the filename, it might be a nightmare for the users to deal with such files.

    3. Reserved file names

      The following filenames are reserved:

      • Windows:

        CON, PRN, AUX, NUL 
        COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
        LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
        

        (both on their own and with arbitrary file extensions, e.g. LPT1.txt).

    4. Other rules

      • Windows:

        Filenames cannot end in a space or dot.

提交回复
热议问题