{"id":42073,"date":"2003-10-22T11:51:00","date_gmt":"2003-10-22T11:51:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/10\/22\/whats-the-deal-with-those-reserved-filenames-like-nul-and-con\/"},"modified":"2003-10-22T11:51:00","modified_gmt":"2003-10-22T11:51:00","slug":"whats-the-deal-with-those-reserved-filenames-like-nul-and-con","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20031022-00\/?p=42073","title":{"rendered":"What&#039;s the deal with those reserved filenames like NUL and CON?"},"content":{"rendered":"\n<p>         Set the wayback machine to DOS 1.0.      <\/p>\n<p>         DOS 1.0 didn&#8217;t support subdirectories, lowercase, or filenames longer than 8.3.      <\/p>\n<p>         When you ran the assembler (or compiler if you were really fancy) the conversation         went something like this:      <\/p>\n<p>         <code>A&gt;asm foo<\/code> &nbsp; &nbsp;<i>the &#8220;.asm&#8221; extension on &#8220;foo&#8221; is implied<\/i>         <br \/>         <code>Assembler version blah blah blah<br \/>         Source file: FOO.ASM<br \/>         Listing file [FOO.LST]:<\/code> &nbsp; &nbsp; <i>just hit Enter to accept the default<\/i>         <br \/>         <code>Object file [FOO.OBJ]:<\/code> &nbsp; &nbsp; <i>just hit Enter to accept the         default<\/i>         <br \/>         <i>Assembler cranks away<\/i>      <\/p>\n<p>         You only had to type the base name of the file; the &#8220;.LST&#8221; and &#8220;.OBJ&#8221; extensions were         appended automatically. In fact, I don&#8217;t think you could disable the extensions; they         were always added.      <\/p>\n<p>         But what if you didn&#8217;t want a listing file? The assembler demanded a filename, and         if you didn&#8217;t type any filename at all, it created one with the same basename as your         source file.      <\/p>\n<p>         That&#8217;s where the magic filenames come in. Suppose you wanted the listing file to go         straight to the printer. You didn&#8217;t want to create a file on your floppy drive because         there might not be enough space to hold it, or just because you didn&#8217;t want to waste         the time creating a file just to delete it anyway. So you typed &#8220;PRN&#8221; as the filename.      <\/p>\n<p>         Now, the assembler doesn&#8217;t know about these magic filenames. So the assembler will         try to create the file &#8220;PRN.LST&#8221; and then start writing to it. Little does the assembler         realize that the output is actually going to the printer.      <\/p>\n<p>         If you wanted to discard the output entirely, you would type &#8220;NUL&#8221;, of course. And         if you wanted it to go to the screen, you would type &#8220;CON&#8221;.      <\/p>\n<p>         Now, if you followed closely, you can see that the above story explains two things         already:      <\/p>\n<ul>\n<li>\n<p>                 Why are the magic filenames magical even if I add an extension?              <\/p>\n<p>                 Answer: If an extension removed the magic, then when the assembler added &#8220;.LST&#8221; to                 the filename, it would no longer be recognized as magical, thereby defeating the purpose                 of the magic.              <\/p>\n<\/li>\n<li>\n<p>                 Why do these magic files exist in every directory?              <\/p>\n<p>                 Answer: Because DOS 1.0 didn&#8217;t have subdirectories. There was only one directory,                 which today we would call the root directory, but back then, since there was no such                 thing as a subdirectory, there was no need to talk about directories in the first                 place, much less give the only one you have a name. It was just called &#8220;the files                 on your disk&#8221;. If magic files didn&#8217;t work in subdirectories, then when you tried to,                 for example, chdir into a subdirectory and then run the assembler, you wouldn&#8217;t be                 able to type &#8220;NUL&#8221; as the filename and get the magic.              <\/p>\n<\/li>\n<\/ul>\n<p>         But why do we carry these magic filenames forward even today?      <\/p>\n<p>         Because everybody still relies on them. Just look at all the batch files that do things         like redirect to &gt;NUL or test if a directory exists by asking &#8220;if exist directoryname\\nul&#8221;,         or all the documentation that says to create a file with &#8220;copy CON &#8230;&#8221;.      <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Set the wayback machine to DOS 1.0. DOS 1.0 didn&#8217;t support subdirectories, lowercase, or filenames longer than 8.3. When you ran the assembler (or compiler if you were really fancy) the conversation went something like this: A&gt;asm foo &nbsp; &nbsp;the &#8220;.asm&#8221; extension on &#8220;foo&#8221; is implied Assembler version blah blah blah Source file: FOO.ASM Listing [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-42073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Set the wayback machine to DOS 1.0. DOS 1.0 didn&#8217;t support subdirectories, lowercase, or filenames longer than 8.3. When you ran the assembler (or compiler if you were really fancy) the conversation went something like this: A&gt;asm foo &nbsp; &nbsp;the &#8220;.asm&#8221; extension on &#8220;foo&#8221; is implied Assembler version blah blah blah Source file: FOO.ASM Listing [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=42073"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=42073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=42073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=42073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}