What's the deal with those reserved filenames like NUL and CON?

Raymond Chen


Set the wayback machine to DOS 1.0.

DOS 1.0 didn’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>asm foo    the “.asm” extension on “foo” is implied
Assembler version blah blah blah
Source file: FOO.ASM
Listing file [FOO.LST]:
    just hit Enter to accept the default
Object file [FOO.OBJ]:     just hit Enter to accept the default
Assembler cranks away

You only had to type the base name of the file; the “.LST” and “.OBJ” extensions were appended automatically. In fact, I don’t think you could disable the extensions; they were always added.

But what if you didn’t want a listing file? The assembler demanded a filename, and if you didn’t type any filename at all, it created one with the same basename as your source file.

That’s where the magic filenames come in. Suppose you wanted the listing file to go straight to the printer. You didn’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’t want to waste the time creating a file just to delete it anyway. So you typed “PRN” as the filename.

Now, the assembler doesn’t know about these magic filenames. So the assembler will try to create the file “PRN.LST” and then start writing to it. Little does the assembler realize that the output is actually going to the printer.

If you wanted to discard the output entirely, you would type “NUL”, of course. And if you wanted it to go to the screen, you would type “CON”.

Now, if you followed closely, you can see that the above story explains two things already:

  • Why are the magic filenames magical even if I add an extension?

    Answer: If an extension removed the magic, then when the assembler added “.LST” to the filename, it would no longer be recognized as magical, thereby defeating the purpose of the magic.

  • Why do these magic files exist in every directory?

    Answer: Because DOS 1.0 didn’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 “the files on your disk”. If magic files didn’t work in subdirectories, then when you tried to, for example, chdir into a subdirectory and then run the assembler, you wouldn’t be able to type “NUL” as the filename and get the magic.

But why do we carry these magic filenames forward even today?

Because everybody still relies on them. Just look at all the batch files that do things like redirect to >NUL or test if a directory exists by asking “if exist directoryname\nul”, or all the documentation that says to create a file with “copy CON …”.


Comments are closed. Login to edit/delete your existing comments