Larry Osterman's WebLog

Confessions of an Old Fogey
Blog - Title

Why is the DOS path character "\"?

Why is the DOS path character "\"?

Rate This
  • Comments 54
Many, many months ago, Declan Eardly asked why the \ character was chosen as the path separator.

The answer's from before my time, but I do remember the original reasons.

It all stems from Microsoft's relationship with IBM.  For DOS 1.0, DOS only supported floppy disks.

Many of the DOS utilities (except for were written by IBM, and they used the "/" character as the "switch" character for their utilities (the "switch" character is the character that's used to distinguish command line switches - on *nix, it's the "-" character, on most DEC operating systems (including VMS, the DECSystem-20 and DECSystem-10), it's the "/" character" (note: I'm grey on whether the "/" character came from IBM or from Microsoft - several of the original MS-DOS developers were old-hand DEC-20 developers, so it's possible that they carried it forward from their DEC background).

The fact that the "/" character conflicted with the path character of another relatively popular operating system wasn't particularly relevant to the original developers - after all, DOS didn't support directories, just files in a single root directory.

Then along came DOS 2.0.  DOS 2.0 was tied to the PC/XT, whose major feature was a 10M hard disk.  IBM asked the Microsoft to add support for hard disks, and the MS-DOS developers took this as an opportunity to add support for modern file APIs - they added a whole series of handle based APIs to the system (DOS 1.0 relied on an application controlled structure called an FCB).  They also had to add support for hierarchical paths.

Now historically there have been a number of different mechanisms for providing hierarchical paths.  The DecSystem-20, for example represented directories as: "<volume>:"<"<Directory>[.<Subdirectory>">"FileName.Extension[,Version]" ("PS:<SYSTEM>MONITR.EXE,4").   VMS used a similar naming scheme, but instead of < and > characters it used [ and ] (and VMS used ";" to differentiate between versions of files).  *nix defines hierarchical paths with a simple hierarchy rooted at "/" - in *nix's naming hierarchy, there's no way of differentiating between files and directories, etc (this isn't bad, btw, it just is).

For MS-DOS 2.0, the designers of DOS chose a hybrid version - they already had support for drive letters from DOS 1.0, so they needed to continue using that.  And they chose to use the *nix style method of specifying a hierarchy - instead of calling the directory out in the filename (like VMS and the DEC-20), they simply made the directory and filename indistinguishable parts of the path.

But there was a problem.  They couldn't use the *nix form of path separator of "/", because the "/" was being used for the switch character.

So what were they to do?  They could have used the "." character like the DEC machines, but the "." character was being used to differentiate between file and extension.  So they chose the next best thing - the "\" character, which was visually similar to the "/" character.

And that's how the "\" character was chosen.

Here's a little known secret about MS-DOS.  The DOS developers weren't particularly happy about this state of affairs - heck, they all used Xenix machines for email and stuff, so they were familiar with the *nix command semantics.  So they coded the OS to accept either "/" or "\" character as the path character (this continues today, btw - try typing "notepad c:/boot.ini"  on an XP machine (if you're an admin)).  And they went one step further.  They added an undocumented system call to change the switch character.  And updated the utilities to respect this flag.

And then they went and finished out the scenario:  They added a config.sys option, SWITCHAR= that would let you set the switch character to "-".

Which flipped MS-DOS into a *nix style system where command lines used "-switch", and paths were / delimited.

I don't know the fate of the switchar API, it's been long gone for many years now.


So that's why the path character is "\".  It's because "/" was taken.

Edit: Fixed title - it's been bugging me all week.


  • For a similar article see entry III.15 in this

    Also to note, / was a common command-line-option indicator in CP/M, and QDOS (which Dos1 was of course based off of) was very much a clone of CP/M.
  • Interesting, I had always wondered why DOS used something different wen UNIX was well established and accepted standard and I sometimes wondered if it was different just for the sake of being different.

    Glad to see that assumption was wrong.
    Not laughing at your post. Just the munging of the title.

    I put in a bug report to the complaining that the HtmlEncoding was messed up, pointing them to the Date&Time munging as an example. Then they sent me an email back that they'd fixed it, and sure enough, your Date&Time title was fixed - it wasn't Date&amp;Time anymore.

    It appears they just hacked up a Replace(overlyescapedtitle, "&amp;", "&") line instead of finding and removing the extra HtmlEncode.


    I laugh so I will not cry...
  • Just wondering about a little detail here:
    "For MS-DOS 2.0, the designers of DOS chose a hybrid version - they already had support for drive letters from DOS 1.0, so they needed to continue using that."

    Where did the drive letters come from, then? I really hate them :) Happily I can, and do, use junctions points now, but you still need to have at least one left. It's so much cleaner with the unified filesystem :) And it is easier to discover special files like the CON, NUL, LPT devices when you can just do
    dir /devices or something like that.
  • Drive letters came about (at least to my understanding) because the first PCs supported two disk drives.

    At the time assigning them letters solved the problem of how to access them. A: for the first drive, B: for the second. When the Hard drive came out it was given drive letter C: because it was the next in line.
  • I don't understand why the switch/parameter character cannot be present in paths. Unix has no problems working with paths that have - in them, most systems, including Windows, can handle paths with spaces in them even though spaces are used to separate arguments and so on.
  • Andreas: *nix commands have no problems with files with "-" in the name?

    How do you remove the file named "-r"?
  • > Where did the drive letters come from, then?

    Why CP/M of course, which QDOS (and hence DOS 1) was a clone of. Read the first chapter of here to see where DOS's real heritage lies...
  • > How do you remove the file named "-r"?

    With "rm -- -r" of course. There's actually quite a few ways to do this.
  • And where did CPM get them from? The DEC operating systems I mentioned above.

    That's also where the copy command and a number of the other command line features of CPM came from.
  • I wish it was possible to have a directory junction pointing at a drive letter for a mounted UNC path. That's the only thing that escapes my amazing single filesystem: I have some stuff that lives on another computer, and there's no way to map L:\My Documents to C:\My Documents were L:\ is a mounted path. It works fine otherwise.

    Why is this the case anyway? Why are mounted UNC paths any different?
  • I'm way too young know this first-hand, so I'll ask.

    Why is there a "\" key on the keyboard in the first place? As far as I know, they aren't used in English grammar, and to this day, most common users don't know which is "back" and which is "forward."

    I suppose I can ask the same about "{" and "}", but I don't mind those as much.

    Since DOS and Windows handle "/" as well as "\", it'd be nice if it would switch to using "/" by default, since Internet URLs use forward slashes, and most people are familiar with them (even though browsers/web servers have to support "\" as well, because of the problem I mentioned earlier, which ultimately lead to security bugs in server-side web software).

    I can't imagine switching to "/" would hurt much backwards compatability, since most path paramters have to be put in quotes these days (thanks to the needlessly long "Document and Settings" and "Program Files").

    I too would like to get rid of drive letters. I'm consdering mounting my all-in-one memory-card reader onto a folder on my hard drive because I'm tired of having C:, D:, E:, F:, G:, H:, I:, J: all show up under My Computer (and X:, Y:, and Z:, but that was my doing). If I mount everything, I can pretend that C: stands for "Computer," but I suspect mounting CD-ROMs causes problems for some pesky copy-protected games (which are another pet peeve of mine).

    I was hoping Monad would help reduce the visibility of drive letters, but I was wrong. It doesn't even support changing the current path to a UNC share, which is a HUGE limitation of both CMD.EXE and any future shells.
  • > Why is there a "\" key on the keyboard in the first place? As far as I know, they aren't used in English grammar, and to this day, most common users don't know which is "back" and which is "forward."

    The backslash was invented by Bob Bemer

    It's use was so you could make the /\ and \/ symbols (AND and OR if you've ever done boolean logic) in the ALGOL language.
  • And of course I meant "its" not "it's". As is oft requested, I wish the msdn blogs had a preview button.
  • > And where did CPM get them from? The DEC operating systems I mentioned above.

    I thought the question was about drive letters specifically.

    An RSX-11 file path looks like DR0:[30,12]FILE.TXT;10

    A CP/M file path for a file on the first floppy looks like

    Tim Patterson who wrote QDOS (the basis for DOS 1) did it based on a CP/M manual. I've never heard it mentioned that he spent any time on any DEC machines.

    There's nothing wrong with DOS originally being a clone of CP/M (similar to how Linux started out as a clone of U*IX), I just think people often gloss over the history.

    My favorite Gary Kildall quote on the issue:
    "Ask Bill [Gates] why the string in function 9 is terminated by a dollar sign. Ask him, because he can't answer, only I know that."
Page 1 of 4 (54 items) 1234