What is the difference between forward slashes and backslashes in paths? [duplicate]

Solution 1:

Unix and its variants have always used the forward slash (/) to denote filesystem hierarchy.

However, Windows owes its filesystem delimiter, the backslash (\), to its MS-DOS predecessor. And MS-DOS wasnt the originator of that. It was brought over from the QDOS operating system (which borrowed from CP/M), which MS bought and reworked into MS-DOS.

Since most, if not all, of web based protocols originated on UNIX (HTTP, FTP, etc.), Microsoft complies with those delimiters to keep compatibility.

Solution 2:

That's not an accurate explanation. The path separator is just a character, a token, that is somewhat arbitrary but usually chosen to mark a natural separation. The backslash as path separator comes from the lineage of CP/M, DOS, and Windows. The slash comes from Unix and possibly other systems before it.

The Internet URL path separator was chosen to be the slash since most of the developers of the standards where familiar with Unix. The Unix slash as path separator is usually considered to be the canonical separator. Its position on the keyboard also makes it easier to type for most people that have to enter it a lot.

Even cross platform scripting languages, such as Python, use the slash is the "normalized form" of specifying paths.

Solution 3:

At an implementation level, windows will handle '/' the same way as '\'. I would just use the '/'. It will make all you applications portable. MySQL and python also translates the '/' to what ever you need on your system, depending one what path separator they use.

The '\' is used in other areas like regular expressions, and some terminals and programming languages as an escape char. That will ensure the next char following it will be interpreted as a literal character, such as \n \r at the end of lines.

As far as notation regarding internal or external systems that is not actually true. The '/' was more popular early on with the *nix systems. Microsoft then become popular and now '\' is what people expect. But as I mentioned Microsoft has to be posix (posix a standard on how operating systems should operate) compliant which means that you could replace all the '\' with '/' in most places and every thing would work with out problems.