Re:Why Does Windows Use Backslash as Path Separator?
by coldpie on Wednesday April 24, 2024 @05:56PM
(#40150235)
Yep. Drives me nuts when I see people fiddling with platform-specific path separators. Just use /, it works everywhere.
Re:Why Does Windows Use Backslash as Path Separator?
by PaulHoule on Wednesday April 24, 2024 @06:01PM
(#40150299)
I am really in the habit of using pathlib in Python and similar facilities in Java so I just write
path = HOME / "cards" / f"{card_id}" / "card.yaml"
Re:Why Does Windows Use Backslash as Path Separator?
by coldpie on Wednesday April 24, 2024 @06:04PM
(#40150334)
You can do, or you can just skip all the spaces and extra quotes and junk and just use literal /.
path = f"{HOME}/cards/{card_id}/card.yaml"
Easier to read & write IMO, and works fine. Even on Windows.
Re:Why Does Windows Use Backslash as Path Separator?
by skinner927 on Wednesday April 24, 2024 @06:21PM
(#40150558)
I really think they goofed Pathlib because of this.
path = Path(“/foo”) / “a” / “b” / “c”
The following is functionally equivalent to the above: path = Path(“/foo”) / “a/b/c”
Which I really think was a mistake. The latter should resolve to “/foo/a\/b\/c” (IMO) because all other invalid characters (like space) are auto-escaped. What’s the point of the overloaded div operator otherwise?
Re:Why Does Windows Use Backslash as Path Separator?
by glandium on Wednesday April 24, 2024 @07:06PM
(#40150974)
space is a valid character in paths. / is not. Never.
Re:Why Does Windows Use Backslash as Path Separator?
by ldjb on Wednesday April 24, 2024 @07:23PM
(#40151171)
Classic Mac OS used colon (:) as the path separator, so slashes were perfectly acceptable in file and directory names.
Even in modern versions of macOS, the GUI still allows you to create files and folders with slashes in their names; the slashes get recorded as colons in the filesystem.
Re:Why Does Windows Use Backslash as Path Separator?
by Zamicol on Wednesday April 24, 2024 @06:03PM
(#40150332)
It's been years since I've had to work on a Windows system, but I'm suspicious of that. Days of my career at the State of Colorado has been spent fixing / problems. Is this something on newer Windows systems?
Re:Why Does Windows Use Backslash as Path Separator?
by coldpie on Wednesday April 24, 2024 @06:06PM
(#40150371)
If you're mucking around with legacy parts of the OS, you might run into troubles. But if you're just doing regular old file I/O from a normal program, nah. Windows doesn't care. You can even mix them.
Re:Why Does Windows Use Backslash as Path Separator?
by RedlineTriad on Thursday April 25, 2024 @06:55AM
(#40155876)
This sadly isn't quite the case as this post demonstrates[0]
> - The path is limited to MAX_PATH (260 chars)
> - Unless you prefix the path with \\?\
> - However using \\?\ disables automatic conversion of / to \ in the path (and some other normalization)
See previous discussion[1]
[0] https://mastodon.gamedev.place/@AshleyGullen/111109299141510...
The major system that won't accept this is cmd.exe so if you are passing parameters to a .bat file that has a filename with a "/" in you will have trouble.