• Greg (unregistered)

    This is going to work fantastically well if someone creates a file on unix that contains a backslash in it's name.

  • A.N.O Nymos (unregistered)

    Just use / for all your path-separators, Windows can handle those just fine.

  • Rainer Deyke (unregistered)

    User code with backslashes as path separators is an abomination. Low level C/C++ file operations support, and have always supported, backslashes.

    Slight exception for the presentation layer, because users expect backslashes. But only the presentation layer. Convert to backslashes on output, convert to forward slashes on input.

  • (nodebb)

    In my decades of software development, different file IO systems were always a pain in the butt. Now these days a lot of people only think there are two but in the past there were many different ones and all of them had a quirk here and there.

    Still, while Windows supports both directory separators, it's very important to note that this support means that all alternative directory separators are actually get converted (normalized) before usage internally and since all functions support const literals that means allocating a buffers. So there is a significant cost involved with using alt directory separators and you still should always use the native versions over the common '/'.

    Now is there a good way to get around this? Nah. There is actually way more to it than just the directory separator since file systems are often completely different in terms of structure and features. Linux is real links and ignoring that could end up in an endless recursion why enumerating directories. Windows had drives, which are not only not bound to letters that can change, they actually often will when you work with multiple removable devices. And finally the whole permission system is completely different, down to what classifies as an executable. And I just mentioned here a few pitfalls on the top of the iceberg. So just using an directory separator macro isn't enough in a well thought out software, you really need to abstract away the OS in a way more involved way to the point that it's really hard to pull this off on a zero cost basis; which means it's often better to do it inline. Sucks for readability, sure, but beats using a bloated, slow, resource hungry IO framework.

    Addendum 2026-06-29 08:01: Linus is real links? Ha, I guess it has them but eh, I blame the heat wave here :-).

  • Frodo Brömmelkamp (unregistered)

    If we're compiling for unix, append a "/" to the filename. Otherwise, append a "". Then we append a path out of an array. Then, if we're on Windows, find all the "/" in our filename and replace them with "". Otherwise, find all the "" in our filename and replace them with "/".

    Ah, the good old XKCD 1638...

  • (nodebb)

    You people had it soft. Welcome to the world of VMS, a.k.a. OpenVMS, in which the directory separator is a period but the entire directory name had to be enclosed in square brackets.

    DISK1:[USERS.JOHNR]README.TXT
    

    And that's just getting started. There was a limit of subdirectory levels (8) but a "logical name" could be defined to sneak around that --- for example, DISK1 might expand to a physical hard drive like DKA0 but it could easily expand to DKA0:[CLIENTS.BESTBUY.CONTRACTS.MAINTENANCE.2020.] instead. Loads of fun for the entire family!

  • (nodebb)

    And somehow, there are still code paths that output the wrong path separator sometimes, though at least modern Windows is forgiving about that

    Indeed, although it is stretching the definition of "modern" a bit, seeing as how all versions of Windows in the NT line supported it, all the way back to 3.1, and the 9x line also supported it. It probably worked (it has been too long since I've needed to know this) on MS-DOS as early as 2.0. (Before that, directory structures weren't a thing on MS-DOS, nor on PC-DOS.)

  • (author) in reply to dpm

    Don't forget the file versions! README.TXT;3 lets you see what the file looked like three versions ago.

    Back when I worked helldesk in college, our mailserver ran off a VAX running VMS. They added a webmail interface in 1998 or 1999 (before that you were expected to just use IMAP or POP), but it was still the same mailserver. And due to the way it worked, you'd get locked out of your account if you exceeded your quota, which meant you couldn't log into the webmail to delete your emails. One of the main tickets for the helldesk drones was telneting into the mailserver using the user's credentials and using the mail CLI tool to clear out old messages.

  • Officer Johnny Holzkopf (unregistered)
    Comment held for moderation.
  • MRAB (unregistered) in reply to A.N.O Nymos

    There are a couple of exceptions. (1) Command line options start with "/". (2) Dialog boxes insist on backslashes.

Leave a comment on “Off the Path”

Log In or post as a guest

Replying to comment #701230:

« Return to Article