Fog Creek Software
Discussion Board

Is there any reason for '\' file separator ?

Does anybody know why Microsoft choose back-slash to be a file-separator ?
IMHO, it only causes a lot's of headaches and ugly "E:\\.." strings ..

Evgeny Goldin
Sunday, February 3, 2002

I guess that one of the possible reasons is that they used slashes for the command line arguments instead of the Unix-like dashes... but that's just a theory :)

Petru Paler
Sunday, February 3, 2002

Many people may argue different symbols are ugly. It is your opinion against theirs in the long run. But i do see your point.


Sunday, February 3, 2002

I read that early versions of MS-DOS did not support subdirectories, so there was no need for a directory separator. Unfortunately, some of the MS-DOS commands used the forward slash character '/' for their command line flags (and still today). This prevented Microsoft from using the forward slash when they eventually introduced subdirectories! Stoopid.

Banana Fred
Sunday, February 3, 2002

In answer to the "what difference does it make?" question, the forward slash is in a generally more convenient position on the keyboard for touch-typists.

On top of this, the backslash has tended to wander from place to place over the years - although these days the disposal of the reverse-L-shaped return key has given it a somewhat standard home below backspace.

Then again, this sort of discussion leads us immediately into the territory of holy wars such as "caps-lock and ctrl should be swapped around."

Charles Miller
Sunday, February 3, 2002

Plus, it drives me mad while programming.  Java .properties files interpret \ as an escape char, which is mindboggling.  And when I'm occassionally writing Python, I often forget if the r"blah" form escapes the \ within the string.

Art Vandelay
Sunday, February 3, 2002

yeah but you can use the :

Sunday, February 3, 2002

Because MS-DOS used the '/' for options, which it got from CP/M, which in turn got it from RX-11, which may have originated it.  When MS-DOS then added support for directories (inspriation from Unix) they had to use something, and that's why they picked '\' although the kernel of MS-DOS itself would understand '/' as well.

So while on the command line you were stuck using '\' in a program, you could do:

fp = fopen("c:/my/dir/to/my/file.txt","r");

and it would work just like:

fp = fopen("c:\my\dir\to\my\file.txt","r");

There was even a hidden MS-DOS call to change the option character under COMMAND.COM but since it was never officially documented, it didn't get widespread use (there was also the inverse call to find out what the option character was currently.  Again, not many programmers, if any, used it).

It wouldn't surprise me to find that the current versions of Windows will still internally support both '/' and '\' as file separators.

-spc (Spent way too much time programming under MS-DOS)

Sean Conner
Sunday, February 3, 2002

It does.

Jay Kint
Monday, February 4, 2002

As well as the API to get and set the switch chararacter, you could also set it in CONFIG.SYS, also a little known, badly documented fact.

At the same time that MS-DOS 2.0 came out, which added sub directories, there was a lot of cross fertilisation from the Xenix group (MS almost had controlling rights over Unix then but let them slip away) so there was a complete set of shell tools, sed, awk, srt and so on. 

I still have them for the curious, and they still work without needing the overhead of Cygnus.

That reminds me that Search was the greatest commandline utility around and ran on my all time favourite machine the Sirius 1 (Victor 9000).

Simon Lucy
Monday, February 4, 2002

Here in the uk the backslash is on the bottom left corner, next to the left shift key.

This is really annoying when your system crashes and the keyboard reverts back to US, and you just can't find the backslash anywhere.

Ged Byrne
Monday, February 4, 2002

I've got it right of '0' here (Sweden). Of course you need to press ALT simultaneously in order to type a '\'. Way to go M$. way to go.

Lennart Fridén
Monday, February 4, 2002

At the time they were making syntax decisions, I'll bet Microsoft's developers didn't expect to sell copies in languages other than English.

And HDOS comes into the story somewhere too (the operating system for Heathkit computers, which Gordon Letwin architected before moving to Microsoft, as I recall. It too used \ as a file separator, if my dim memories are correct.

Mike Gunderloy
Monday, February 4, 2002

> Of course you need to press ALT simultaneously in order to type a '\'.

ALT GR, actually.  the ALT key on the left side of the keyboard doesn't work, so you have to press both keys with the same hand.

(the backslash isn't much of a problem compared to {[]} which are placed on the 7, 8, 9, and 0 keys in the top row).

> Way to go M$

I think you need to study a bit more computer history...

Fredrik Lundh
Monday, February 4, 2002

I use some Japanese Windows NT machines at work and, for some silly reason, the backslash key ASCII code maps to the Yen symbol.. so all subdirectories are delimited using the Yen symbol!  :-\

Banana Fred
Monday, February 4, 2002

I had no idea the / could be used in DOS.

Even more curious...

This works:  cd /somedir\anotherdir

Greg Davis
Monday, February 4, 2002

It should also be remembered that MS didn't write DOS 1.0.  They licensed Seattle DOS from Seattle Computer Products because they needed something fast in order to get into the original IBM PC.  So, in fact, they didn't pick '/' as switch character; they inherited it.

When it came time for DOS 2.0, which supported hard drives and needed tree-structured directories (and which they DID write), they had to use a different character, and for whatever reasons they picked the backslash.  The forward slash being unavailable, it was probably as good a choice as any.

Chris Dunford
Tuesday, February 5, 2002

I said this works:    cd /somedir\anotherdir

Turns out it only work in XP.

Who knew they were adding features to the

I'd heard vague rumors that it was slated for removal... 

must have been FUD

Greg Davis
Tuesday, February 5, 2002

Hm... here, in Chile, we have three keyboard variants. Most of them use the '\' in the place where the '~' is located in US keyboards (below ESC.) We have to press Alt GR in order to get it.

Also, in our keyboards, there is no '~', so we have to use Alt-126...

Leonardo Herrera
Wednesday, February 6, 2002

Still now, most "users" do not know the "\" character.
Ever thought that it was a way to dissuade "ignorants" from making disasters all over the HD?
MS introduced hidden files in DOS and early WIN, then somebody decided to make hidden files visible !!!
Now, I appreciate, hidden is hidden again (as default at least).

Easy typing is anyway referred only to the US keyboard, don't blame only MS, just think about the semicolumn, graphs or square brackets of Pascal/Delphi.

Matheus Moeller
Wednesday, February 6, 2002

Speaking of strange syntax like cd /wherever\whenever working on XP, the one syntax I miss is the cd ... type syntax that was on NT 4.0, it worked to any depth too, somehow typing cd ..... was a lot handier than cd ..\..\..\..
just one of those little things that I wish existed everywhere.

Plus whenever you are feeling that the \ is too much hassle just be thankful you aren't using VAX VMS.
cd dirname
is a lot handier than
set def [.dirname]
similarly cd .. beats set def [-] everytime.

Wakka Wakka Wakka
Friday, February 8, 2002

Yes I know ,  the "/"  was used as command line args.
Also in the pre 6.x dos you can change the "\" to other characters via a dos call.

bill malcolm
Friday, May 28, 2004

*  Recent Topics

*  Fog Creek Home