{"id":14211,"date":"2026-06-03T02:00:00","date_gmt":"2026-06-03T06:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14211"},"modified":"2026-05-19T12:38:46","modified_gmt":"2026-05-19T16:38:46","slug":"spaces-in-dos-filenames-part-2","status":"publish","type":"post","link":"http:\/\/www.both.org\/?p=14211","title":{"rendered":"Spaces in DOS filenames, part 2"},"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=\"14211\" 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\">I recently answered a question about &#8220;can FreeDOS use spaces in filenames?&#8221; The short answer is <a href=\"https:\/\/www.both.org\/?p=14209\">yes, if the spaces are between other characters<\/a> in the filename. I gave an example that you can have a file named <code>MY\u23b5FILE.TXT<\/code> with the space in the middle, but not <code>MYFILE\u23b5.TXT<\/code> where the space is after the <em>base name<\/em> in the filename. (In this example, I&#8217;ve typed each space as <code>\u23b5<\/code> so you can see it.) Let&#8217;s explore why DOS filenames have this limitation with spaces.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"filenames\">8.3 filenames<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">DOS saves files using a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Design_of_the_FAT_file_system#DIR\">File Allocation Table<\/a> where filenames are stored <a href=\"https:\/\/en.wikipedia.org\/wiki\/8.3_filename#Directory_table\">in a particular way<\/a>: the first two fields are the <em>filename<\/em> and <em>extension<\/em>. The <em>filename<\/em> is always stored as 8 characters, and the extension is always 3 characters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each field is padded with spaces. That means if you save a file as <code>FILE.C<\/code>, that&#8217;s 4 characters for the <em>filename<\/em> part and 1 character for the <em>extension<\/em>. Behind the scenes, DOS saves this as an &#8220;8.3&#8221; filename, with extra character padded as spaces: <code>FILE\u23b5\u23b5\u23b5\u23b5.C\u23b5\u23b5<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-test-program\">A test program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s create a short test program that saves a new file using a space at the <em>end<\/em> of the <em>filename<\/em> part. In this case, we&#8217;ll write a text file called <code>BB\u23b5.TXT<\/code> (there&#8217;s a space after the <code>BB<\/code> and before the <code>.TXT<\/code>) that saves just as single line of text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-1\"><\/a>#include &lt;stdio.h>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-2\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-3\"><\/a>int main()\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-4\"><\/a>{\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-5\"><\/a>  FILE *f;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-6\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-7\"><\/a>  f = fopen(\"BB .TMP\", \"w\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-8\"><\/a>  if (f==NULL) {\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-9\"><\/a>    puts(\"error, cannot open file\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-10\"><\/a>    return 1;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-11\"><\/a>  }\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-12\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-13\"><\/a>  fputs(\"Hello world\\n\", f);\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-14\"><\/a>  fclose(f);\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-15\"><\/a>\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-16\"><\/a>  puts(\"Ok\");\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-17\"><\/a>  return 0;\n<a href=\"file:\/\/\/home\/jhall\/Documents\/markdown\/both\/spaces2.html#cb1-18\"><\/a>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just to explain a few things here: the <code>fopen<\/code> statement opens a file called <code>BB\u23b5.TMP<\/code> for <strong>w<\/strong>riting. If this file doesn&#8217;t exist, the program will create it automatically. Then it saves the text <code>Hello world<\/code> to the file, and closes it before the program ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can compile this program using any C compiler. On FreeDOS, we include several C compiler in the FreeDOS distribution, including Open Watcom C, IA-16 GCC, and BCC; these are all in the &#8220;Development&#8221; package group on the BonusCD. Let&#8217;s save this test program as <code>bb.c<\/code> and compile it using Open Watcom C:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;wcl -q bb.c\nDOS\/4GW Protected Mode Run-time  Version 1.97\nCopyright (c) Rational Systems, Inc. 1990-1994\nDOS\/4GW Protected Mode Run-time  Version 1.97\nCopyright (c) Rational Systems, Inc. 1990-1994<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-q<\/code> command line option makes Open Watcom run in <strong>q<\/strong>uiet mode, so it doesn&#8217;t print any extra text. The other output you see isn&#8217;t actually from the C compiler, but from the DOS\/4GW program, which is a DOS &#8220;extender&#8221; that Open Watcom uses. If you don&#8217;t want this extra output, set the <code>DOS4G<\/code> environment variable to <code>quiet<\/code> and DOS\/4GW won&#8217;t print anything. Let&#8217;s compile with Open Watcom C one more time, with DOS\/4GW running in &#8220;quiet&#8221; mode, but without Open Watcom&#8217;s <code>-q<\/code> command line option, to show the normal compiler output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;set DOS4G=quiet\nD:\\SRC&gt;wcl bb.c\nOpen Watcom C\/C++16 Compile and Link Utility Version 1.9\nPortions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.\nSource code is available under the Sybase Open Watcom Public License.\nSee http:\/\/www.openwatcom.org\/ for details.\n        wcc BB.C\nOpen Watcom C16 Optimizing Compiler Version 1.9\nPortions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.\nSource code is available under the Sybase Open Watcom Public License.\nSee http:\/\/www.openwatcom.org\/ for details.\nBB.C: 18 lines, included 771, 0 warnings, 0 errors\nCode size: 59\n        wlink @__wcl__.lnk\nOpen Watcom Linker Version 1.9\nPortions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.\nSource code is available under the Sybase Open Watcom Public License.\nSee http:\/\/www.openwatcom.org\/ for details.\nloading object files\nsearching libraries\ncreating a DOS executable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s a lot of extra text. You can see why I usually compile using the <code>-q<\/code> (<strong>q<\/strong>uiet) command line option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"spaces-in-filenames\">Spaces in filenames<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After compiling the test program, let&#8217;s run it to create a new <code>BB\u23b5.TMP<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;bb.exe\nOk<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program prints an <code>Ok<\/code> message to indicate it was able to save a new file called <code>BB\u23b5.TMP<\/code>. But if we look for the new file, we&#8217;ll see that it doesn&#8217;t have the space after the <code>BB<\/code> <em>filename<\/em> part:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\SRC&gt;dir \/b *.tmp\nBB.TMP<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is because the DOS filesystem pads out the 8-character filename with spaces, so <code>BB\u23b5.TMP<\/code> actually gets saved as <code>BB\u23b5\u23b5\u23b5\u23b5\u23b5\u23b5.TMP<\/code> (that&#8217;s <code>BB<\/code> plus 6 spaces, then the <code>TMP<\/code> extension). In fact, saving a file like <code>BB.TMP<\/code> would also get stored the same way: <code>BB<\/code> plus 6 spaces, then the extension.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DOS filenames are 8.3, space padded, so you cannot have spaces at the end<\/p>\n","protected":false},"author":33,"featured_media":3514,"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-14211","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\/14211","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=14211"}],"version-history":[{"count":1,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14211\/revisions"}],"predecessor-version":[{"id":14212,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14211\/revisions\/14212"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3514"}],"wp:attachment":[{"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14211"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}