Which characters are invalid for an MS-DOS filename?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
16
down vote

favorite
2












I'm writing a filename I/O procedure in x86-16 assembly language. It takes eight characters (I don't need to support long filenames) from the keyboard and prints them to an on-screen text input field.



At the moment I'm allowing numbers, upper/lower-case letters, underscores, and hyphens.



I'd like to allow all legal symbols, but I can't find an official list of banned characters. Common sense tells me that slashes are illegal, but if I had to guess, I would say that the plus character is legal. (edit: It's not!)



I'm already ignoring the period character since my code automatically handles appending the period and file extension.










share|improve this question



















  • 17




    You might also find Retrocomputing useful.
    – Bob
    Sep 28 at 7:27










  • Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
    – Mixxiphoid
    Sep 28 at 9:49










  • @Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
    – phuclv
    Sep 28 at 14:44






  • 1




    @phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
    – Mixxiphoid
    Sep 28 at 14:46











  • Why all MS-DOS symbols? Why not also consider other older OS rules?
    – jpmc26
    Sep 30 at 0:45














up vote
16
down vote

favorite
2












I'm writing a filename I/O procedure in x86-16 assembly language. It takes eight characters (I don't need to support long filenames) from the keyboard and prints them to an on-screen text input field.



At the moment I'm allowing numbers, upper/lower-case letters, underscores, and hyphens.



I'd like to allow all legal symbols, but I can't find an official list of banned characters. Common sense tells me that slashes are illegal, but if I had to guess, I would say that the plus character is legal. (edit: It's not!)



I'm already ignoring the period character since my code automatically handles appending the period and file extension.










share|improve this question



















  • 17




    You might also find Retrocomputing useful.
    – Bob
    Sep 28 at 7:27










  • Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
    – Mixxiphoid
    Sep 28 at 9:49










  • @Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
    – phuclv
    Sep 28 at 14:44






  • 1




    @phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
    – Mixxiphoid
    Sep 28 at 14:46











  • Why all MS-DOS symbols? Why not also consider other older OS rules?
    – jpmc26
    Sep 30 at 0:45












up vote
16
down vote

favorite
2









up vote
16
down vote

favorite
2






2





I'm writing a filename I/O procedure in x86-16 assembly language. It takes eight characters (I don't need to support long filenames) from the keyboard and prints them to an on-screen text input field.



At the moment I'm allowing numbers, upper/lower-case letters, underscores, and hyphens.



I'd like to allow all legal symbols, but I can't find an official list of banned characters. Common sense tells me that slashes are illegal, but if I had to guess, I would say that the plus character is legal. (edit: It's not!)



I'm already ignoring the period character since my code automatically handles appending the period and file extension.










share|improve this question















I'm writing a filename I/O procedure in x86-16 assembly language. It takes eight characters (I don't need to support long filenames) from the keyboard and prints them to an on-screen text input field.



At the moment I'm allowing numbers, upper/lower-case letters, underscores, and hyphens.



I'd like to allow all legal symbols, but I can't find an official list of banned characters. Common sense tells me that slashes are illegal, but if I had to guess, I would say that the plus character is legal. (edit: It's not!)



I'm already ignoring the period character since my code automatically handles appending the period and file extension.







filenames ms-dos data-validation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 28 at 14:40









phuclv

8,36163486




8,36163486










asked Sep 28 at 4:06









My life is a bug.

28311




28311







  • 17




    You might also find Retrocomputing useful.
    – Bob
    Sep 28 at 7:27










  • Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
    – Mixxiphoid
    Sep 28 at 9:49










  • @Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
    – phuclv
    Sep 28 at 14:44






  • 1




    @phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
    – Mixxiphoid
    Sep 28 at 14:46











  • Why all MS-DOS symbols? Why not also consider other older OS rules?
    – jpmc26
    Sep 30 at 0:45












  • 17




    You might also find Retrocomputing useful.
    – Bob
    Sep 28 at 7:27










  • Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
    – Mixxiphoid
    Sep 28 at 9:49










  • @Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
    – phuclv
    Sep 28 at 14:44






  • 1




    @phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
    – Mixxiphoid
    Sep 28 at 14:46











  • Why all MS-DOS symbols? Why not also consider other older OS rules?
    – jpmc26
    Sep 30 at 0:45







17




17




You might also find Retrocomputing useful.
– Bob
Sep 28 at 7:27




You might also find Retrocomputing useful.
– Bob
Sep 28 at 7:27












Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
– Mixxiphoid
Sep 28 at 9:49




Try to create a folder in Windows and put a '?' in the name. A tooltip tells you which characters are forbidden. This gives you a start :)...
– Mixxiphoid
Sep 28 at 9:49












@Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
– phuclv
Sep 28 at 14:44




@Mixxiphoid that won't work because the set of allowed characters in Windows are much larger. For example +,;, space and a-z are allowed in Windows but not DOS. Explorer gives me the error "A file name can't contain any of the following characters / : * ? " < > | which is just a subset of the banned characters in DOS
– phuclv
Sep 28 at 14:44




1




1




@phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
– Mixxiphoid
Sep 28 at 14:46





@phuclv that is why I said 'This gives you a start' and also why this is a comment and not an answer.
– Mixxiphoid
Sep 28 at 14:46













Why all MS-DOS symbols? Why not also consider other older OS rules?
– jpmc26
Sep 30 at 0:45




Why all MS-DOS symbols? Why not also consider other older OS rules?
– jpmc26
Sep 30 at 0:45










4 Answers
4






active

oldest

votes

















up vote
29
down vote



accepted










A concise summary can be found on Wikipedia:




Legal characters for DOS filenames include the following:



  • Upper case letters A–Z

  • Numbers 0–9

  • Space (though trailing spaces in either the base name or the extension are considered to be padding and not a part of the filename, also filenames with spaces in them must be enclosed in quotes to be used on a DOS command line, and if the DOS command is built programmatically, the filename must be enclosed in quadruple quotes when viewed as a variable within the program building the DOS command.)

  • ! # $ % & ' ( ) - @ ^ _ ` ~

  • Values 128–255 (though if NLS services are active in DOS, some characters interpreted as lowercase are invalid and unavailable)

This excludes the following ASCII characters:




  • " * + , / : ; < = > ? [ ] | [9]

  • Windows/MS-DOS has no shell escape character


  • . (U+002E . full stop) within name and extension fields, except in . and .. entries (see below)

  • Lower case letters a–z (stored as A–Z on FAT12/FAT16)

  • Control characters 0–31

  • Value 127 (DEL)[dubious – discuss]



https://en.wikipedia.org/wiki/8.3_filename#Directory_table



And here's what MS-DOS 6 user guide officially said




Naming Files and Directories



Every file and directory, except for the root directory on each drive, must have a name. The following list summarizes the rules for naming files and directories. File and directory names:



  • Can be up to eight characters long. In addition, you can include an extension up to three characters long.

  • Are not case-sensitive. It does not matter whether you use uppercase or lowercase letters when you type them.

  • Can contain only the letters A through Z, the numbers 0 through 9, and the following special characters: underscore (_), caret (^), dollar sign ($), tilde (~), exclamation point (!), number sign (#), percent sign (%), ampersand (&), hyphen (-), braces (), at sign (@), single quotation mark (`), apostrophe ('), and parentheses (). No other special characters are acceptable.

  • Cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

  • Cannot be identical to the name of another file or subdirectory in the same directory.



  • Concise User’s Guide - Microsoft® MS-DOS® 6

  • Concise User’s Guide - Microsoft® MS-DOS® 6 - alternate link

This is from PC-DOS 7:




The name you assign to a file must meet the following criteria:



  • It can contain no more than eight characters.


  • It can consist of the letters A through Z, the numbers 0 through 9, and the following special characters:



    _ underscore ^ caret
    $ dollar sign ~ tilde
    ! exclamation point # number sign
    % percent sign & ampersand
    - hyphen braces
    @ at sign ` single quote
    ' apostrophe () parentheses


Note: No other special characters are acceptable.



  • The name cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

  • The name cannot be one of the following reserved file names: CLOCK$, CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, LPT4, NUL, and PRN.

  • It cannot be the same name as another file within the directory.



User's Guide - PC DOS 7




The first byte of a name must not be 0x20 (space). Short names or extensions are padded with spaces. Special ASCII characters 0x22 ("), 0x2a (*), 0x2b (+), 0x2c (,), 0x2e (.), 0x2f (/), 0x3a (:), 0x3b (;), 0x3c (<), 0x3d (=), 0x3e (>), 0x3f (?), 0x5b ([), 0x5c (), 0x5d (]), 0x7c (|) are not allowed.




The FAT filesystem



If you're also interested in MS-DOS 5.0 then here it is.






share|improve this answer


















  • 11




    It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
    – Thomas Schremser
    Sep 28 at 10:42







  • 3




    @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
    – RobIII
    Sep 28 at 14:23






  • 1




    @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
    – Quantic
    Sep 28 at 18:31











  • It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
    – ale10ander
    Sep 28 at 18:41






  • 2




    @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
    – phuclv
    Sep 28 at 19:06


















up vote
12
down vote













Strictly speaking, as an MS/PC/DR-DOS applications programmer you are supposed to ask the operating system for this information. INT 0x21 with AX=0x6505 returns a pointer to the so-called FCHAR NLS table for your country and code page. This table lists a range of characters and a further set of characters that terminate filenames.



In theory it varies by country and code page. But the fact that it was not formally carried over into the OS/2 Control Program API and the fact that FreeDOS has 1 table across all codepages and countries show that it is largely invariant in practice.



Further reading



  • http://ctyme.com/intr/rb-3163.htm

  • http://ctyme.com/intr/rb-3163.htm#Table1754





share|improve this answer



























    up vote
    10
    down vote













    I found this in a manual for MS-DOS 3.3. I'm running 6.22, but it probably still applies. I was wrong about '+' being allowed.



    Enter image description here






    share|improve this answer


















    • 2




      A manual from back-in-the-day is more reliable than Wikipedia
      – Stewart
      Sep 28 at 12:53










    • @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
      – phuclv
      Sep 28 at 15:52


















    up vote
    3
    down vote













    If you just want to validate the filename, you may want to use INT 21H/AH=60H (TRUENAME - CANONICALIZE FILENAME OR PATH) after ensuring that the passed filename doesn't have a colon or backslash (those may be treated as drive letters and directories): the function takes your proposed filename and tries to canonicalize it by uppercasing the letters and checking for invalid characters (it also adds a drive letter/server name and path.)



    In pseudocode:



    If !(filename contains "/", "", ".", ":")
    Canonicalize filename (INT 21H/AH=60H)
    If !(CF is set) filename is valid
    Filename is not valid





    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "3"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1362080%2fwhich-characters-are-invalid-for-an-ms-dos-filename%23new-answer', 'question_page');

      );

      Post as a guest






























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      29
      down vote



      accepted










      A concise summary can be found on Wikipedia:




      Legal characters for DOS filenames include the following:



      • Upper case letters A–Z

      • Numbers 0–9

      • Space (though trailing spaces in either the base name or the extension are considered to be padding and not a part of the filename, also filenames with spaces in them must be enclosed in quotes to be used on a DOS command line, and if the DOS command is built programmatically, the filename must be enclosed in quadruple quotes when viewed as a variable within the program building the DOS command.)

      • ! # $ % & ' ( ) - @ ^ _ ` ~

      • Values 128–255 (though if NLS services are active in DOS, some characters interpreted as lowercase are invalid and unavailable)

      This excludes the following ASCII characters:




      • " * + , / : ; < = > ? [ ] | [9]

      • Windows/MS-DOS has no shell escape character


      • . (U+002E . full stop) within name and extension fields, except in . and .. entries (see below)

      • Lower case letters a–z (stored as A–Z on FAT12/FAT16)

      • Control characters 0–31

      • Value 127 (DEL)[dubious – discuss]



      https://en.wikipedia.org/wiki/8.3_filename#Directory_table



      And here's what MS-DOS 6 user guide officially said




      Naming Files and Directories



      Every file and directory, except for the root directory on each drive, must have a name. The following list summarizes the rules for naming files and directories. File and directory names:



      • Can be up to eight characters long. In addition, you can include an extension up to three characters long.

      • Are not case-sensitive. It does not matter whether you use uppercase or lowercase letters when you type them.

      • Can contain only the letters A through Z, the numbers 0 through 9, and the following special characters: underscore (_), caret (^), dollar sign ($), tilde (~), exclamation point (!), number sign (#), percent sign (%), ampersand (&), hyphen (-), braces (), at sign (@), single quotation mark (`), apostrophe ('), and parentheses (). No other special characters are acceptable.

      • Cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • Cannot be identical to the name of another file or subdirectory in the same directory.



      • Concise User’s Guide - Microsoft® MS-DOS® 6

      • Concise User’s Guide - Microsoft® MS-DOS® 6 - alternate link

      This is from PC-DOS 7:




      The name you assign to a file must meet the following criteria:



      • It can contain no more than eight characters.


      • It can consist of the letters A through Z, the numbers 0 through 9, and the following special characters:



        _ underscore ^ caret
        $ dollar sign ~ tilde
        ! exclamation point # number sign
        % percent sign & ampersand
        - hyphen braces
        @ at sign ` single quote
        ' apostrophe () parentheses


      Note: No other special characters are acceptable.



      • The name cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • The name cannot be one of the following reserved file names: CLOCK$, CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, LPT4, NUL, and PRN.

      • It cannot be the same name as another file within the directory.



      User's Guide - PC DOS 7




      The first byte of a name must not be 0x20 (space). Short names or extensions are padded with spaces. Special ASCII characters 0x22 ("), 0x2a (*), 0x2b (+), 0x2c (,), 0x2e (.), 0x2f (/), 0x3a (:), 0x3b (;), 0x3c (<), 0x3d (=), 0x3e (>), 0x3f (?), 0x5b ([), 0x5c (), 0x5d (]), 0x7c (|) are not allowed.




      The FAT filesystem



      If you're also interested in MS-DOS 5.0 then here it is.






      share|improve this answer


















      • 11




        It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
        – Thomas Schremser
        Sep 28 at 10:42







      • 3




        @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
        – RobIII
        Sep 28 at 14:23






      • 1




        @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
        – Quantic
        Sep 28 at 18:31











      • It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
        – ale10ander
        Sep 28 at 18:41






      • 2




        @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
        – phuclv
        Sep 28 at 19:06















      up vote
      29
      down vote



      accepted










      A concise summary can be found on Wikipedia:




      Legal characters for DOS filenames include the following:



      • Upper case letters A–Z

      • Numbers 0–9

      • Space (though trailing spaces in either the base name or the extension are considered to be padding and not a part of the filename, also filenames with spaces in them must be enclosed in quotes to be used on a DOS command line, and if the DOS command is built programmatically, the filename must be enclosed in quadruple quotes when viewed as a variable within the program building the DOS command.)

      • ! # $ % & ' ( ) - @ ^ _ ` ~

      • Values 128–255 (though if NLS services are active in DOS, some characters interpreted as lowercase are invalid and unavailable)

      This excludes the following ASCII characters:




      • " * + , / : ; < = > ? [ ] | [9]

      • Windows/MS-DOS has no shell escape character


      • . (U+002E . full stop) within name and extension fields, except in . and .. entries (see below)

      • Lower case letters a–z (stored as A–Z on FAT12/FAT16)

      • Control characters 0–31

      • Value 127 (DEL)[dubious – discuss]



      https://en.wikipedia.org/wiki/8.3_filename#Directory_table



      And here's what MS-DOS 6 user guide officially said




      Naming Files and Directories



      Every file and directory, except for the root directory on each drive, must have a name. The following list summarizes the rules for naming files and directories. File and directory names:



      • Can be up to eight characters long. In addition, you can include an extension up to three characters long.

      • Are not case-sensitive. It does not matter whether you use uppercase or lowercase letters when you type them.

      • Can contain only the letters A through Z, the numbers 0 through 9, and the following special characters: underscore (_), caret (^), dollar sign ($), tilde (~), exclamation point (!), number sign (#), percent sign (%), ampersand (&), hyphen (-), braces (), at sign (@), single quotation mark (`), apostrophe ('), and parentheses (). No other special characters are acceptable.

      • Cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • Cannot be identical to the name of another file or subdirectory in the same directory.



      • Concise User’s Guide - Microsoft® MS-DOS® 6

      • Concise User’s Guide - Microsoft® MS-DOS® 6 - alternate link

      This is from PC-DOS 7:




      The name you assign to a file must meet the following criteria:



      • It can contain no more than eight characters.


      • It can consist of the letters A through Z, the numbers 0 through 9, and the following special characters:



        _ underscore ^ caret
        $ dollar sign ~ tilde
        ! exclamation point # number sign
        % percent sign & ampersand
        - hyphen braces
        @ at sign ` single quote
        ' apostrophe () parentheses


      Note: No other special characters are acceptable.



      • The name cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • The name cannot be one of the following reserved file names: CLOCK$, CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, LPT4, NUL, and PRN.

      • It cannot be the same name as another file within the directory.



      User's Guide - PC DOS 7




      The first byte of a name must not be 0x20 (space). Short names or extensions are padded with spaces. Special ASCII characters 0x22 ("), 0x2a (*), 0x2b (+), 0x2c (,), 0x2e (.), 0x2f (/), 0x3a (:), 0x3b (;), 0x3c (<), 0x3d (=), 0x3e (>), 0x3f (?), 0x5b ([), 0x5c (), 0x5d (]), 0x7c (|) are not allowed.




      The FAT filesystem



      If you're also interested in MS-DOS 5.0 then here it is.






      share|improve this answer


















      • 11




        It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
        – Thomas Schremser
        Sep 28 at 10:42







      • 3




        @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
        – RobIII
        Sep 28 at 14:23






      • 1




        @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
        – Quantic
        Sep 28 at 18:31











      • It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
        – ale10ander
        Sep 28 at 18:41






      • 2




        @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
        – phuclv
        Sep 28 at 19:06













      up vote
      29
      down vote



      accepted







      up vote
      29
      down vote



      accepted






      A concise summary can be found on Wikipedia:




      Legal characters for DOS filenames include the following:



      • Upper case letters A–Z

      • Numbers 0–9

      • Space (though trailing spaces in either the base name or the extension are considered to be padding and not a part of the filename, also filenames with spaces in them must be enclosed in quotes to be used on a DOS command line, and if the DOS command is built programmatically, the filename must be enclosed in quadruple quotes when viewed as a variable within the program building the DOS command.)

      • ! # $ % & ' ( ) - @ ^ _ ` ~

      • Values 128–255 (though if NLS services are active in DOS, some characters interpreted as lowercase are invalid and unavailable)

      This excludes the following ASCII characters:




      • " * + , / : ; < = > ? [ ] | [9]

      • Windows/MS-DOS has no shell escape character


      • . (U+002E . full stop) within name and extension fields, except in . and .. entries (see below)

      • Lower case letters a–z (stored as A–Z on FAT12/FAT16)

      • Control characters 0–31

      • Value 127 (DEL)[dubious – discuss]



      https://en.wikipedia.org/wiki/8.3_filename#Directory_table



      And here's what MS-DOS 6 user guide officially said




      Naming Files and Directories



      Every file and directory, except for the root directory on each drive, must have a name. The following list summarizes the rules for naming files and directories. File and directory names:



      • Can be up to eight characters long. In addition, you can include an extension up to three characters long.

      • Are not case-sensitive. It does not matter whether you use uppercase or lowercase letters when you type them.

      • Can contain only the letters A through Z, the numbers 0 through 9, and the following special characters: underscore (_), caret (^), dollar sign ($), tilde (~), exclamation point (!), number sign (#), percent sign (%), ampersand (&), hyphen (-), braces (), at sign (@), single quotation mark (`), apostrophe ('), and parentheses (). No other special characters are acceptable.

      • Cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • Cannot be identical to the name of another file or subdirectory in the same directory.



      • Concise User’s Guide - Microsoft® MS-DOS® 6

      • Concise User’s Guide - Microsoft® MS-DOS® 6 - alternate link

      This is from PC-DOS 7:




      The name you assign to a file must meet the following criteria:



      • It can contain no more than eight characters.


      • It can consist of the letters A through Z, the numbers 0 through 9, and the following special characters:



        _ underscore ^ caret
        $ dollar sign ~ tilde
        ! exclamation point # number sign
        % percent sign & ampersand
        - hyphen braces
        @ at sign ` single quote
        ' apostrophe () parentheses


      Note: No other special characters are acceptable.



      • The name cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • The name cannot be one of the following reserved file names: CLOCK$, CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, LPT4, NUL, and PRN.

      • It cannot be the same name as another file within the directory.



      User's Guide - PC DOS 7




      The first byte of a name must not be 0x20 (space). Short names or extensions are padded with spaces. Special ASCII characters 0x22 ("), 0x2a (*), 0x2b (+), 0x2c (,), 0x2e (.), 0x2f (/), 0x3a (:), 0x3b (;), 0x3c (<), 0x3d (=), 0x3e (>), 0x3f (?), 0x5b ([), 0x5c (), 0x5d (]), 0x7c (|) are not allowed.




      The FAT filesystem



      If you're also interested in MS-DOS 5.0 then here it is.






      share|improve this answer














      A concise summary can be found on Wikipedia:




      Legal characters for DOS filenames include the following:



      • Upper case letters A–Z

      • Numbers 0–9

      • Space (though trailing spaces in either the base name or the extension are considered to be padding and not a part of the filename, also filenames with spaces in them must be enclosed in quotes to be used on a DOS command line, and if the DOS command is built programmatically, the filename must be enclosed in quadruple quotes when viewed as a variable within the program building the DOS command.)

      • ! # $ % & ' ( ) - @ ^ _ ` ~

      • Values 128–255 (though if NLS services are active in DOS, some characters interpreted as lowercase are invalid and unavailable)

      This excludes the following ASCII characters:




      • " * + , / : ; < = > ? [ ] | [9]

      • Windows/MS-DOS has no shell escape character


      • . (U+002E . full stop) within name and extension fields, except in . and .. entries (see below)

      • Lower case letters a–z (stored as A–Z on FAT12/FAT16)

      • Control characters 0–31

      • Value 127 (DEL)[dubious – discuss]



      https://en.wikipedia.org/wiki/8.3_filename#Directory_table



      And here's what MS-DOS 6 user guide officially said




      Naming Files and Directories



      Every file and directory, except for the root directory on each drive, must have a name. The following list summarizes the rules for naming files and directories. File and directory names:



      • Can be up to eight characters long. In addition, you can include an extension up to three characters long.

      • Are not case-sensitive. It does not matter whether you use uppercase or lowercase letters when you type them.

      • Can contain only the letters A through Z, the numbers 0 through 9, and the following special characters: underscore (_), caret (^), dollar sign ($), tilde (~), exclamation point (!), number sign (#), percent sign (%), ampersand (&), hyphen (-), braces (), at sign (@), single quotation mark (`), apostrophe ('), and parentheses (). No other special characters are acceptable.

      • Cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • Cannot be identical to the name of another file or subdirectory in the same directory.



      • Concise User’s Guide - Microsoft® MS-DOS® 6

      • Concise User’s Guide - Microsoft® MS-DOS® 6 - alternate link

      This is from PC-DOS 7:




      The name you assign to a file must meet the following criteria:



      • It can contain no more than eight characters.


      • It can consist of the letters A through Z, the numbers 0 through 9, and the following special characters:



        _ underscore ^ caret
        $ dollar sign ~ tilde
        ! exclamation point # number sign
        % percent sign & ampersand
        - hyphen braces
        @ at sign ` single quote
        ' apostrophe () parentheses


      Note: No other special characters are acceptable.



      • The name cannot contain spaces, commas, backslashes, or periods (except the period that separates the name from the extension).

      • The name cannot be one of the following reserved file names: CLOCK$, CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, LPT4, NUL, and PRN.

      • It cannot be the same name as another file within the directory.



      User's Guide - PC DOS 7




      The first byte of a name must not be 0x20 (space). Short names or extensions are padded with spaces. Special ASCII characters 0x22 ("), 0x2a (*), 0x2b (+), 0x2c (,), 0x2e (.), 0x2f (/), 0x3a (:), 0x3b (;), 0x3c (<), 0x3d (=), 0x3e (>), 0x3f (?), 0x5b ([), 0x5c (), 0x5d (]), 0x7c (|) are not allowed.




      The FAT filesystem



      If you're also interested in MS-DOS 5.0 then here it is.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Sep 30 at 0:39









      Peter Mortensen

      8,237166184




      8,237166184










      answered Sep 28 at 4:39









      phuclv

      8,36163486




      8,36163486







      • 11




        It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
        – Thomas Schremser
        Sep 28 at 10:42







      • 3




        @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
        – RobIII
        Sep 28 at 14:23






      • 1




        @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
        – Quantic
        Sep 28 at 18:31











      • It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
        – ale10ander
        Sep 28 at 18:41






      • 2




        @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
        – phuclv
        Sep 28 at 19:06













      • 11




        It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
        – Thomas Schremser
        Sep 28 at 10:42







      • 3




        @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
        – RobIII
        Sep 28 at 14:23






      • 1




        @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
        – Quantic
        Sep 28 at 18:31











      • It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
        – ale10ander
        Sep 28 at 18:41






      • 2




        @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
        – phuclv
        Sep 28 at 19:06








      11




      11




      It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
      – Thomas Schremser
      Sep 28 at 10:42





      It might be worth noting that even though they only contain valid characters the special filenames CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 are also not permitted (see here)
      – Thomas Schremser
      Sep 28 at 10:42





      3




      3




      @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
      – RobIII
      Sep 28 at 14:23




      @ThomasSchremser "Do not use", "Avoid" and "Not recommended" is not the same as "not permitted".
      – RobIII
      Sep 28 at 14:23




      1




      1




      @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
      – Quantic
      Sep 28 at 18:31





      @RobIII Yes but they linked to "Windows > Desktop" documentation, not to "MS-DOS" documentation. The wiki for DOS says, "There are reserved device names in DOS that cannot be used as filenames regardless of extension as they are occupied by built-in character devices". In other words, not permitted in DOS and some versions of Windows, and not recommended in other Windows versions.
      – Quantic
      Sep 28 at 18:31













      It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
      – ale10ander
      Sep 28 at 18:41




      It's interesting that the ` is referred to as a single quote. I've always heard it called a backtick, and the ' (what they call (not incorrectly) an apostrophe) as a single quote.
      – ale10ander
      Sep 28 at 18:41




      2




      2




      @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
      – phuclv
      Sep 28 at 19:06





      @ale10ander yeah that surprised me to. I've always hated that many people use it for the apostrophe (like in I`m) or the begin part of the quote. For example GNU documentations always write `like this' which is very ugly and less readable to me
      – phuclv
      Sep 28 at 19:06













      up vote
      12
      down vote













      Strictly speaking, as an MS/PC/DR-DOS applications programmer you are supposed to ask the operating system for this information. INT 0x21 with AX=0x6505 returns a pointer to the so-called FCHAR NLS table for your country and code page. This table lists a range of characters and a further set of characters that terminate filenames.



      In theory it varies by country and code page. But the fact that it was not formally carried over into the OS/2 Control Program API and the fact that FreeDOS has 1 table across all codepages and countries show that it is largely invariant in practice.



      Further reading



      • http://ctyme.com/intr/rb-3163.htm

      • http://ctyme.com/intr/rb-3163.htm#Table1754





      share|improve this answer
























        up vote
        12
        down vote













        Strictly speaking, as an MS/PC/DR-DOS applications programmer you are supposed to ask the operating system for this information. INT 0x21 with AX=0x6505 returns a pointer to the so-called FCHAR NLS table for your country and code page. This table lists a range of characters and a further set of characters that terminate filenames.



        In theory it varies by country and code page. But the fact that it was not formally carried over into the OS/2 Control Program API and the fact that FreeDOS has 1 table across all codepages and countries show that it is largely invariant in practice.



        Further reading



        • http://ctyme.com/intr/rb-3163.htm

        • http://ctyme.com/intr/rb-3163.htm#Table1754





        share|improve this answer






















          up vote
          12
          down vote










          up vote
          12
          down vote









          Strictly speaking, as an MS/PC/DR-DOS applications programmer you are supposed to ask the operating system for this information. INT 0x21 with AX=0x6505 returns a pointer to the so-called FCHAR NLS table for your country and code page. This table lists a range of characters and a further set of characters that terminate filenames.



          In theory it varies by country and code page. But the fact that it was not formally carried over into the OS/2 Control Program API and the fact that FreeDOS has 1 table across all codepages and countries show that it is largely invariant in practice.



          Further reading



          • http://ctyme.com/intr/rb-3163.htm

          • http://ctyme.com/intr/rb-3163.htm#Table1754





          share|improve this answer












          Strictly speaking, as an MS/PC/DR-DOS applications programmer you are supposed to ask the operating system for this information. INT 0x21 with AX=0x6505 returns a pointer to the so-called FCHAR NLS table for your country and code page. This table lists a range of characters and a further set of characters that terminate filenames.



          In theory it varies by country and code page. But the fact that it was not formally carried over into the OS/2 Control Program API and the fact that FreeDOS has 1 table across all codepages and countries show that it is largely invariant in practice.



          Further reading



          • http://ctyme.com/intr/rb-3163.htm

          • http://ctyme.com/intr/rb-3163.htm#Table1754






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 28 at 10:31









          JdeBP

          22.1k14886




          22.1k14886




















              up vote
              10
              down vote













              I found this in a manual for MS-DOS 3.3. I'm running 6.22, but it probably still applies. I was wrong about '+' being allowed.



              Enter image description here






              share|improve this answer


















              • 2




                A manual from back-in-the-day is more reliable than Wikipedia
                – Stewart
                Sep 28 at 12:53










              • @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
                – phuclv
                Sep 28 at 15:52















              up vote
              10
              down vote













              I found this in a manual for MS-DOS 3.3. I'm running 6.22, but it probably still applies. I was wrong about '+' being allowed.



              Enter image description here






              share|improve this answer


















              • 2




                A manual from back-in-the-day is more reliable than Wikipedia
                – Stewart
                Sep 28 at 12:53










              • @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
                – phuclv
                Sep 28 at 15:52













              up vote
              10
              down vote










              up vote
              10
              down vote









              I found this in a manual for MS-DOS 3.3. I'm running 6.22, but it probably still applies. I was wrong about '+' being allowed.



              Enter image description here






              share|improve this answer














              I found this in a manual for MS-DOS 3.3. I'm running 6.22, but it probably still applies. I was wrong about '+' being allowed.



              Enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 30 at 0:40









              Peter Mortensen

              8,237166184




              8,237166184










              answered Sep 28 at 4:19









              My life is a bug.

              28311




              28311







              • 2




                A manual from back-in-the-day is more reliable than Wikipedia
                – Stewart
                Sep 28 at 12:53










              • @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
                – phuclv
                Sep 28 at 15:52













              • 2




                A manual from back-in-the-day is more reliable than Wikipedia
                – Stewart
                Sep 28 at 12:53










              • @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
                – phuclv
                Sep 28 at 15:52








              2




              2




              A manual from back-in-the-day is more reliable than Wikipedia
              – Stewart
              Sep 28 at 12:53




              A manual from back-in-the-day is more reliable than Wikipedia
              – Stewart
              Sep 28 at 12:53












              @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
              – phuclv
              Sep 28 at 15:52





              @Stewart what's important are the quotes on Wikipedia, not Wikipedia itself. If in doubt just check the footnotes and references in the article @Mylifeisabug I've just added the MS-DOS 6 manual
              – phuclv
              Sep 28 at 15:52











              up vote
              3
              down vote













              If you just want to validate the filename, you may want to use INT 21H/AH=60H (TRUENAME - CANONICALIZE FILENAME OR PATH) after ensuring that the passed filename doesn't have a colon or backslash (those may be treated as drive letters and directories): the function takes your proposed filename and tries to canonicalize it by uppercasing the letters and checking for invalid characters (it also adds a drive letter/server name and path.)



              In pseudocode:



              If !(filename contains "/", "", ".", ":")
              Canonicalize filename (INT 21H/AH=60H)
              If !(CF is set) filename is valid
              Filename is not valid





              share|improve this answer
























                up vote
                3
                down vote













                If you just want to validate the filename, you may want to use INT 21H/AH=60H (TRUENAME - CANONICALIZE FILENAME OR PATH) after ensuring that the passed filename doesn't have a colon or backslash (those may be treated as drive letters and directories): the function takes your proposed filename and tries to canonicalize it by uppercasing the letters and checking for invalid characters (it also adds a drive letter/server name and path.)



                In pseudocode:



                If !(filename contains "/", "", ".", ":")
                Canonicalize filename (INT 21H/AH=60H)
                If !(CF is set) filename is valid
                Filename is not valid





                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  If you just want to validate the filename, you may want to use INT 21H/AH=60H (TRUENAME - CANONICALIZE FILENAME OR PATH) after ensuring that the passed filename doesn't have a colon or backslash (those may be treated as drive letters and directories): the function takes your proposed filename and tries to canonicalize it by uppercasing the letters and checking for invalid characters (it also adds a drive letter/server name and path.)



                  In pseudocode:



                  If !(filename contains "/", "", ".", ":")
                  Canonicalize filename (INT 21H/AH=60H)
                  If !(CF is set) filename is valid
                  Filename is not valid





                  share|improve this answer












                  If you just want to validate the filename, you may want to use INT 21H/AH=60H (TRUENAME - CANONICALIZE FILENAME OR PATH) after ensuring that the passed filename doesn't have a colon or backslash (those may be treated as drive letters and directories): the function takes your proposed filename and tries to canonicalize it by uppercasing the letters and checking for invalid characters (it also adds a drive letter/server name and path.)



                  In pseudocode:



                  If !(filename contains "/", "", ".", ":")
                  Canonicalize filename (INT 21H/AH=60H)
                  If !(CF is set) filename is valid
                  Filename is not valid






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 29 at 0:59









                  ErikF

                  2393




                  2393



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1362080%2fwhich-characters-are-invalid-for-an-ms-dos-filename%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?