Since when does Windows support forward slash as path separator?
retrocomputing.stackexchange.com
retrocomputing.stackexchange.com
More than ten years later and I still think it was the right choice.
All in all, I think the Java world suffers majorly from that extreme abstractions. Never in my life have I worked in a language/ecosystem with more (and often unnecessary) abstractions than in Java. Pretty good language overall, but the culture could really benefit from some good old fashioned pragmatism
(Not intended to be sarcastic, just in case it comes off that way. I only add the "useless layer of complexity" because it makes the intention more explicit for me.)
To see this in action, open a terminal, type:
touch test:file.txt
Then open Finder and browse to whatever folder you were in and you'll see a file called test/file.txt.I'm not sure which is the native representation, but I do know that every API I've used to interact with the filesystem on macOS has used slashes as the path separator, so GP should be fine. But it's definitely a fun party trick to pull out around unsuspecting Mac users.
If that execution is handled by a shell instead of going directly through an operating system's CreateProcess() function, then the command line string may be mangled either by the shell, or some other "helpful" code sitting inbetween which tries to resolve backslash-escapes (which are usually needed in front of quotation marks).
It a very typical problem in cross-platform Python code, and I think I also stumbled over it in Node.js.
The canonical way to solve this would be to pass the components of that command line through a function that escapes or quotes anything that needs to be escaped. In Ruby and when using bash for example we have [0].
Does Windows have something similar?
[0]: https://ruby-doc.org/stdlib-2.5.1/libdoc/shellwords/rdoc/She...
E.g. the following two are the same:
ipconfig/all
ipconfig /all
I always wonder how exactly this is implemented (and why?!).Edit: oh, another more famous example is the equivalence of
cd..
cd ..
And I have to admit I still do `ls..` from time to time, since I used Windows first (and most).What was implemented, though, was a set of characters that acted as separators between the command name and the rest of the command tail. To many people's surprise in years gone by, this included not just whitespace but things like forward slashes and equals signs and commas. If memory serves, there was even an undocumented NLSFUNC table for looking them up, although my memory might be mis-serving me here.
So one could, for example, treat the COMMAND command line as if it were CONFIG.SYS and do SOMETHING=ARGUMENTS, which was particularly useful for the built-in PATH and DPATH commands.
MS/PC/DR-DOS, and indeed OS/2, programs were passed not a set of arguments but a single command tail, limited to 126 characters on MS/PC/DR-DOS and limited to 64KiB for the whole command-tail(s)-plus-environment-strings on OS/2. (It was the runtime libraries of programs written in programming languages such as C that did of all of the fakery that pretended that there was an argv[], and notably there were slight disagreements between Microsoft, Borland, and Watcom on the wild edge cases.) Usually, the first character of this command tail was the whitespace separator character that got entered by the user. But it didn't have to be.
For a while, I think it was the only supported way to have paths longer than 260 characters, so I've seen some high level APIs add it to the path to work around issues (C# used to do this in some paths, not sure if it still will).
It might be rare, but as someone that's had to debug a "why doesn't c:/whatever/data.dat work but c:\whatever\data.dat does?" issue, I err on using the correct file separator.
the fact that CMD.EXE (or COMMAND.COM in earlier versions) famously did (and still does) NOT support it has many people confused.
CMD.EXE does support forward slash paths. But some of its commands you have to quote a path containing forward slashes, or else it will think it is an option character.
For example, `type c:/windows/win.ini` will give a syntax error. But `type "c:/windows/win.ini"` will do what you expect. By contrast, `cd c:/windows` just works.
COMMAND.COM is a different story, in part because unlike CMD.EXE, COMMAND.COM doesn't support quoting of paths. Although, while CMD.EXE is fine with `cd c:/windows`, COMMAND.COM rejects it.
[0] Amazing that win.ini is still there after all these years, but it is just a vestige for 16-bit app support–although still present on 64-bit systems that don't support 16-bit apps.
> Newer Windows Versions (NT and later) copied that behaviour > Windows applications did not always follow and may or may not accept either when parsing for filenames.
Meaning it _may_ work but it also may not.
The Windows API has always supported forward slash, going back to Windows 3.x, probably even back to 1.x and 2.x. For example, if you run NOTEPAD.EXE in Windows 3.1 [0], and type a path like c:/windows into the File>Open dialog box, it is accepted just as c:\windows would be
However, COMMAND.COM doesn't support forward slash, because of its use as an option character. (Unless you used the undocumented SWITCHAR setting to change the option character to a dash/hyphen, but that setting was disabled in DOS 3 onwards.) CMD.EXE partially has the same problem, although it can be worked around with quoting, which COMMAND.COM doesn't support.
Applications have always been a mixed bag though – including under that label Microsoft products, and even utilities included with DOS/Windows. Although, nowadays it is rare to find applications with that problem, but I'm sure if you go back far enough it would have been much more common. The explosion in popularity of the web and also of Linux and macOS has made Windows app developers (and even users) much more forward-slash-aware than they used to be.
Heck, one could even cite Peter Norton on the pathname separators, writing the The dissection of DOS 3.0 article in his column in the 1984-10-30 edition (volume 3 number 21) of PC magazine.
Feed a windows-style path or line ending to linux? Watch how it dies with absurd errors.
PS C:\> Get-PSDrive C,S,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem C:\Users\jtm
S FileSystem C:\Users\jtm
HKLM Registry
PS C:\Users\jtm> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem C:\Users\jtm
S FileSystem C:\Users\jtm
HKCU Registry
HKLM Registry
PS C:\Users\jtm> cd HKLM:
PS HKLM:\> cd ~
Set-Location: Home location for this provider is not set. To set the home location, call "(get-psprovider 'Registry').Home = 'path'".
PS HKLM:\> (Get-Location).Provider.Home = 'C:\Program Files\Microsoft Office'
PS HKLM:\> cd ~
PS C:\Program Files\Microsoft Office> (Get-Location).Provider.Home = 'HKLM:\SYSTEM\CurrentControlSet'
PS C:\Program Files\Microsoft Office> cd S:
PS S:\> cd ~
PS HKLM:\SYSTEM\CurrentControlSet> (Get-Location).Provider.Home = '..'
PS HKLM:\SYSTEM\CurrentControlSet> cd ~
PS HKLM:\SYSTEM> cd ~
PS HKLM:\> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem HKLM:\SYSTEM\CurrentControlSet
S FileSystem HKLM:\SYSTEM\CurrentControlSet
HKCU Registry ..
HKLM Registry ..
PS HKLM:\>