It annoys me having used Unix in college and now working on the Windows side. What's the history behind this decision? Anyone know why it worked out this way?
-
[Slash versus backslash as directory separator - what/who caused this rift?](https://retrocomputing.stackexchange.com/q/4695/1981) – phuclv Aug 13 '18 at 16:56
2 Answers
Unix introduced / as the directory separator sometime around 1970. I don't know why exactly this character was chosen; the ancestor system Multics used >, but the designers of Unix had already used > together with < for redirection in the shell (see Why is the root directory denoted by a / sign?).
MS-DOS 2.0 introduced \ as the directory separator in the early 1980s. The reason / was not used is that MS-DOS 1.0 (which did not support directories at all) was already using / to introduce command-line options. It took this usage of / from CP/M, which took it from VMS. You can read a more thorough explanation of why that choice was made on Larry Osterman's blog (MS-DOS even briefly had an option to change the option character to - and the directory separator to /, but it didn't stick).
/ it is recognized by most programmer-level APIs (in all versions of DOS and Windows). So you can often, but not always get away with using / as a directory separator under Windows. A notable exception is that you can't use / as a separator after the \\? prefix which (even in Windows 7) is the only way to specify a path using Unicode or containing more than 260 characters.
Some user interface elements support / as a directory separator under Windows, but not all. Some programs just pass filenames through to the underlying API, so they support / and \ indifferently. In the command interpreter (in command.com or cmd), you can use / in many cases, but not always; this is partly dependent on the version of Windows (for example, cd /windows works in XP and 7 but did not in Windows 9x). The Explorer path entry box accepts / (at least from XP up; probably because it also accepts URLs). On the other hand, the standard file open dialog rejects slashes.
- 53
- 5
- 69,786
- 21
- 137
- 178
-
2`/` is recognized as a directory separator by the MS-DOS or Windows command-line. – Tamara Wijsman Aug 16 '10 at 14:05
-
2
-
1@TomWij: Do you have a reference as to where precisely `/` is accepted on the command line? For example, what does `dir /p` do? and `dir c:/p`? and `c:/windows/notepad.exe`? and `start /windows/notepad.exe`? etc. (I don't have a Windows machine here to test.) – Gilles 'SO- stop being evil' Aug 16 '10 at 14:25
-
http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx - File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections. - The command line uses this File I/O functions. – Tamara Wijsman Aug 16 '10 at 14:28
-
1@Andrew: thanks. All I could scrounge up on short notice is a Windows 98, where `cd /windows` does not work. – Gilles 'SO- stop being evil' Aug 16 '10 at 20:56
-
3`/` was probably used as the directory separator in UNIX because it was an easy (unshifted) key to strike on a Teletype. The unshifted special characters were `: - ; , . /`. – Daniel R Hicks Mar 21 '14 at 19:21
-
It should be noted that MS-DOS was a rebranding of QDOS (Quick and Dirty OS) produced by Seattle Computer Products. QDOS, in turn, was written to mimic CP/M-86. I don't know whether either of those products used `/` for options, though. – Daniel R Hicks Mar 21 '14 at 19:28
-
@DanielRHicks CP/M used `/` for options, and that is indeed where DOS got it from (as I mention in my answer). – Gilles 'SO- stop being evil' Mar 21 '14 at 20:22
-
CP/M didn't get anything from VMS. Perhaps the other way around. CP/M was first written in 1975. VMS was not even a dream then. – Greg A. Woods Nov 03 '15 at 23:08
-
5Interestingly enough, I recently dug through DOS 1 and 2 sources and manuals and found out that Microsoft used `/` (and `-` for switches) like Xenix, and inspired by Xenix, but IBM released before Microsoft shipped to OEMs, and IBM used `\` (and `/` for switches) and changed the prompt from `A:` to `A>` so they changed the default and shipped buggy (still assuming `/`/`-`) documentation plus a note that it was changed and why. – mirabilos Apr 11 '16 at 11:18
-
IIRC, Unix introduced `/` because its development went hand-in-hand with the C language, where the backslash is used in escape sequences. – Ralfonso Mar 02 '17 at 18:15
-
@AndrewJ.Brehm Using `/` as leading separator would be very bad practice. I just tested with `\d`, `\dd`, and `\tt` as directory names: while `cd /tt` works, `cd /d` gives an error, and `cd /dd` enters the `\d` directory!—This said, `cd D:/dd` works well. – Yongwei Wu Apr 29 '23 at 06:20
The underlying Windows API can accept either the backslash or slash to separate directory and file components of a path, but the Microsoft convention is to use a backslash, and APIs that return paths put backslash in.
MS-DOS 2.0 copied the hierarchical file system from Unix and thus used the forward slash, but (possibly on the insistence of IBM) added the backslash to allow paths to be typed into the command shell while retaining compatibility with MS-DOS 1.0 and CP/M where the slash was the command-line option indicator.
- Compare
dir/w, which shows the current directory in wide format, againstdir\w, which runs the filewwithin thedirdirectory.
References:
- 7,052
- 7
- 27
- 48
- 57,083
- 27
- 185
- 256