{"id":14209,"date":"2026-05-29T02:00:00","date_gmt":"2026-05-29T06:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14209"},"modified":"2026-05-19T12:33:16","modified_gmt":"2026-05-19T16:33:16","slug":"yes-dos-filenames-can-have-spaces","status":"publish","type":"post","link":"http:\/\/www.both.org\/?p=14209","title":{"rendered":"Yes, DOS filenames can have spaces"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14209\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">Someone asked me recently if FreeDOS supports spaces in filenames. <a href=\"https:\/\/www.freedos.org\/\">FreeDOS<\/a> is an open source DOS-compatible operating system that you can use to play classic DOS games, run legacy business software, or write new DOS programs. Any program that works on MS-DOS should also run on FreeDOS. And that means FreeDOS comes with the same limitations as classic DOS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DOS uses <a href=\"https:\/\/en.wikipedia.org\/wiki\/8.3_filename\">8.3 filenames<\/a>, which means filenames can only have up to 8 characters for the <em>base name<\/em> and up to 3 characters for the <em>extension<\/em>. Filenames are stored in all-uppercase, but are actually case insensitive. That means if you save as file as <code>MYFILE.TXT<\/code> you can also access it as <code>Myfile.txt<\/code> or <code>MyFile.Txt<\/code> or any other mix of uppercase and lowercase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use almost any character in a filename, but in practice this is usually letters, numbers, and certain punctuation characters like <code>!<\/code>, <code>#<\/code>, <code>$<\/code>, <code>%<\/code>, <code>(<\/code>, <code>)<\/code>, <code>-<\/code>, <code>_<\/code>, <code>{<\/code>, <code>}<\/code>, <code>_<\/code>, and a few other characters. You cannot use some other characters like quotes, question marks, slashes, square brackets, colon or semicolon, periods, commas, greater-than or less-than (plus a few more), which would get in the way of the shell.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But space is technically allowed in 8.3 filenames. Although in practice it&#8217;s not a good idea to use them, because some applications may not support spaces in filenames in the same way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"lets-try-it\">Let&#8217;s try it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Whenever you have a question about something, like <em>can a filename have a space in it<\/em>, I recommend writing a quick program to test it. So let&#8217;s write a test program that creates a new text file with a space in the filename, writes a short message, and saves it. This program does just that, saving the file as <code>A A.TMP<\/code>. Note that the space must be <em>surrounded<\/em> by other valid characters. For example, you can name a file as <code>MY FILE.TXT<\/code> but not <code>MYFILE .TXT<\/code> where the space is at the end of the <em>base name<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-1\"><\/a>#include &lt;stdio.h&gt;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-2\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-3\"><\/a>int main()\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-4\"><\/a>{\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-5\"><\/a>  FILE *f;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-6\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-7\"><\/a>  f = fopen(\"A A.TMP\", \"w\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-8\"><\/a>  if (f==NULL) {\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-9\"><\/a>    puts(\"error, cannot open file\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-10\"><\/a>    return 1;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-11\"><\/a>  }\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-12\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-13\"><\/a>  fputs(\"Hello world\\n\", f);\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-14\"><\/a>  fclose(f);\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-15\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-16\"><\/a>  puts(\"Ok\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-17\"><\/a>  return 0;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces.html#cb1-18\"><\/a>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;s not much going on inside this program, because it&#8217;s meant to test a specific thing. The <code>fopen<\/code> line opens a file called <code>A A.TMP<\/code> for <strong>w<\/strong>riting. The <code>if<\/code> statement after that checks if the file could be opened; if it could not, the program prints an error and immediately quits. Otherwise, the program writes <code>Hello world<\/code> to the file, then closes it before printing an &#8220;Ok&#8221; message and returning to the operating system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;ve written this program on FreeDOS, you can compile it with any C compiler. We include several C compilers on the FreeDOS distribution, including Open Watcom C, an IA-16 version of GCC, and BCC. I saved this program as <code>aa.c<\/code> and compiled it with Open Watcom C. (Open Watcom prints a lot of messages as it goes, but I&#8217;ve made it <strong>q<\/strong>uiet with the <code>-q<\/code> option. I also prevented the DOS4G extender from printing a message by setting the <code>DOS4G<\/code> environment variable to <code>quiet<\/code>.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;set DOS4G=quiet\nD:\\SRC&gt;wcl -q aa.c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just run the program, and you&#8217;ll see that it creates a new file called <code>A A.TMP<\/code> (there&#8217;s a space in between the two <strong>A<\/strong>&#8216;s).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;dir \/b *.tmp\nFile not found.\n\nD:\\SRC&gt;aa.exe\nOk\n\nD:\\SRC&gt;dir \/b *.tmp\nA A.TMP<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can access the file using quotes on the command line. But because the filename has <code>TMP<\/code> for the extension, you can also use a wildcard for other actions such as deleting the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;type \"A A.TMP\"\nHello world\n\nD:\\SRC&gt;del *.tmp\none file removed.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-caution\">A caution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is a valid C program and it will compile using any standard C compiler. However, note that some C compilers may alter the behavior because of spaces in the filename. Notably, the runtime library in BCC (Bruce&#8217;s C Compiler) prevents spaces in filenames, replacing them with underscore characters. So if you compile this program with BCC and run it, you will get slightly different behavior.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;bcc -o aa.com aa.c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now run the program and you will instead get a file called <code>A_A.TMP<\/code> (with an underscore instead of a space).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;aa.com\nOk\n\nD:\\SRC&gt;dir \/b *.tmp\nA_A.TMP\n\nD:\\SRC&gt;type A_A.TMP\nHello world<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A short program to demonstrate that yes, DOS filenames can have spaces in them<\/p>\n","protected":false},"author":33,"featured_media":7678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[340,150],"tags":[267,152],"class_list":["post-14209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freedos","category-programming","tag-freedos","tag-programming"],"modified_by":"Jim Hall","_links":{"self":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14209"}],"version-history":[{"count":1,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14209\/revisions"}],"predecessor-version":[{"id":14210,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14209\/revisions\/14210"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/7678"}],"wp:attachment":[{"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14209"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}