So what IS the right direction of the path's slash (/ or \) under Windows?

Windows is the bastard child of operating systems in this regard, but a lot of APIs will accept forward slashes as well. On Windows, a file path looks like this:

C:\Users\jsmith\Documents\file.txt

On a Unix-like system (including Mac OS X and Linux), the same path would look like this:

/home/jsmith/Documents/file.txt

A URL, standardized in RFC 1738, always uses forward slashes, regardless of platform:

http://home.example.com/Documents/file.txt

The reason for this is historical. Not even Windows can reverse our thinking on URLs. When you're talking about backslashes, the only platform you'll find that uses them is Windows (and some other novelty ones).

Where you might see backslashes used other than Windows would be UNC paths -- however, Windows is the chief proponent of these as well:

\\HOMESVR\Documents\file.txt

And whatever you do, don't make a commercial for your Web site and say "my company dot com back slash promotion".


A file path and a URI are different. \ is correct in a Windows file path and / is correct in a URI.

So this file path: C:\Documents\Foo translates to this URI: file:///C:/Documents/Foo


The reason for this is a little piece of history. When UNIX was created, or should I rather say UNICS, they chose the / as separator for directories. Back in the days, storage media was rather small, and every directory in the root was another mounted storage device (/bin /lib etc.)

When Microsoft release MS-DOS version 1.0, it did not have directory support. They used the / character for parameters from programs (program /a /b)

MS-DOS 1.0, a quick rebrand of Q-DOS, is a CP/M derived operating system, from which it inherited drive letters (A: C: etc.)

As in later versions they wanted to add some directory support, they chose to use the \ since the / already had another meaning in their operating system.

There are many artifacts of computer history in modern operating systems, which I suppose most people don't realize, but still have a major influence on how they work.

So, what is the right way? If there is any, I would say it's the / because UNIX-like operating systems were out there way before Microsoft implemented directory support into their DOS.