-
Feature Articles
- Most Recent Articles
- The Easy No
- Flushed Out
- The Hot Fix
- The Roadmap
- Let's Be Facebook!
- Whales Ahoy!
- Three Digit Acronyms
- The Pride Goeth
- CodeSOD
-
Error'd
- Most Recent Articles
- Princess Pricing
- Einfach so
- Kaids Hen 2025
- Fi fa foe
- Microbits
- No Rush
- Bridge for Sale
- Super SEO Strategies
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This is going to work fantastically well if someone creates a file on unix that contains a backslash in it's name.
Admin
Just use / for all your path-separators, Windows can handle those just fine.
Admin
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.
Admin
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 :-).
Admin
Ah, the good old XKCD 1638...
Admin
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.
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!
Admin
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.)
Admin
Don't forget the file versions!
README.TXT;3lets 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
mailCLI tool to clear out old messages.Admin
It's not just about the path separator. Things that also matter are maximum directory depth, maximum file name length, forbidden characters (like "screenshot_2026-06-29_16:28:03.jpg" could be a problem), as well as possible displaying problems with mangled character sets and encodings (UTF-8 vs. ISO-8859-1 vs. CP-1252 vs. maybe even CP-850), as well as entirely "forbidden" filenames (such as "CON:"). Also characters can have special meanings, but still could be allowed in filenames elsewhere ("3*3 matrix.pdf", "What's up?.Doc", "yes|no.txt", "My $5.png", "read THIS »handbook«.xlsx", "sys1.stupid.tasks(gohome).jcl", "LOGIN.COM;1" and so on). Being truly cross-platform with paths and filenames is not easy if you want to leverage the "strange" (but valid) possibilites...
Admin
There are a couple of exceptions. (1) Command line options start with "/". (2) Dialog boxes insist on backslashes.
Admin
Seems like a backslash backlash flashback!
Admin
I often worked very carefully to make sure my shell scripts worked ok even for names containing spaces, backslashes, shell wildcards, and the dreaded "newline". Perl made it much easier, as you got globbing only in very specific circumstances.
Admin
In VMS README.TXT;3 is the third version, not the version 3 back.
Admin
Entirely possible. I haven't actually used it since 2002. Which is honestly, kinda shockingly late to be using a VAX.
Admin
Yep, just use a forward slash.
Admin
"Windows" might handle it, but you can bet that the non-standard filename will leak into some context that won't. When in Redmond, do as the Redmonders do.
Admin
Actually, README.TXT;-3 would give you "three versions back".
Admin
I’m also worried about that ReplaceAll, which is a normal CS 102 assignment, but I’ve seen poorly implemented versions that somehow break on simple things
Admin
In my file abstraction on Windows I'm converting everything to UNC format at the file API layer. Internally paths and files are always regular slashes as they work mostly. Some APIs unfortunately won't like them, so it's a bit hit and miss.
Also, for funny file systems, there's Guardian on the HPE Nonstop (formerly known as Tandem): $<drive name>.<volume>.<filename>
I don't know about drive names, but both volume (a single sub folder) and filename are 8 characters max. No Z or digit as first file name letter (Z is reserved)
Admin
Not at all. I worked at a company in late 1999 which had their whole production like controlled by a VAX. In fact, for strategic reasons they used Windows, Linux & VMS for different parts of their business to not rely on a single vendor. After that job I was always baffled how risky other IT infrastructures were in comparison. But to be fair, most of them weren't businesses that lost millions if the production was standing still for a minute.
Admin
Does that many that any of those 3 vendors could cause a disruption of their production?
Admin
It's quite possible to create a file called "CON" on Windows. The mapping from names like CON to actual device drivers is done by the top-level file system parser, and you can, using documented methods (the infamous backslash-backslash-dot-backslash thing), bypass the top-level parser, and if you do that, two big things happen:
First, the limit of 260 characters for the whole pathname goes "poof", replaced by a limit of 32767 (wide) characters.
Second, those "special" names are no longer special.
The price is that you have to do a bunch of the other work the top-level parser does, such that you present the APIs with a full absolute path name, with no elements called "." or "..", and backslashes everywhere - no forward slashes allowed, etc.
Admin
TRWTF happens when people pass a path with backslashes as a regex pattern without properly quoting it. They even tried to be clean and used
os.path.septo append the proper separator to the "pattern". Of course <eof> is not a proper escape sequence for a regex pattern....Admin
Ah no. As I said, different parts of the business used different OS. They used VMS for the production line, Linux for R&D and Windows for the less important people like administration, office and management. They did that also with other software, they used MS Office but used a Lotus Notes mail cluster f.e.
They only downside you have is that you need a bigger pool of experts maintaining the infrastructure, but you are not vendor locked because the biggest hurdle of migrations is lack of expert know-how. And people like 20yr old me with experience in all three OS were useful as well, that's how I got the job back then. So you end up with a healthy mix of experts and generalists.
But yeah, it's not the cheapest solution. However that has been a world-wide operating company which a brand portfolio everyone has already heard of, so for them a few thousand bucks is just a rounding error.
Admin
Fun thing about the VMS paths: you could access a disk on a different machine
DIR MAVEN::Disk1:[dir.subdir]file.ext;-2
and the ;-2 means "get the version that two versions out of date", which was a hoot and a half. You can also put in a user name and password
DIR MAVEN"myname password::Disk$1:[dir.subdir]file.ext
Admin
Last time I used a VAX was 1989 at Kodak Japan. The versioned files were both a blessing and a curse. It was nice being able to revert, but with a minuscule disk quota we'd have to carefully choose which versions to keep around.
Admin
Windows may be forgiving about this, but Linux absolutely is not, and it doesn't even have the courtesy to punish you right. It will accept your UNC path and blindly try to access the file in some subdirectory of your current directory (heaven help you if you were calling
mkdir()) rather than tell you UNC paths are not supported.Admin
Oh sure, let's turn every filesystem call into Clippy.
Admin
macOS is even more fun, since for a lot of its history, the path separator was the colon ("Macintosh HD:Folder1:Folder 2:...". I remember getting bugs on why they were seeing paths with colons in them, but I couldn't do anything about it because that's what the macOS APIs used. And yes, this was OS X - you could use /, but many APIs internally convert it to a colon when dealing with HFS+.
Admin
since / is not valid in a windows filename, if you do come across something that doesn't accept / as a separator, you can safely replace / with \
Admin
POSIX does not restrict Unix system from having backslashes in filenames, and block devices are migratable. Second-guessing backslashes at the OS level or above would be perverse and harmful.
Admin
Archimedes and family (RISC OS) also used dots as file separators. Also, each file had a hidden file type (similar to a file extension). These were not part of the file name per se, so you had to add this in the conversion if you copied them to other systems.
Admin
If a filename needed an extension (because the file had come from a MS-DOS), a slash was used, so MS-DOS "ReadMe.txt" became "ReadMe/txt".
Admin
That's precisely the reproach. IIRC it also allows control codes, for extra insanity.
Addendum 2026-07-02 12:12: I'd add that anyone who willing puts a backslash or a control code in a UNIX filename is looking for trouble.
Admin
It's a foolish reproach. Backslashes are part of ASCII, and the user is entitled to use them if the file system doesn't.
Admin
PS: yes, there are ASCII characters that "may be asking for trouble" in a filename, which is why POSIX defines a safe character set, but such "trouble" in userland programs is the burden of those programs, not of the OS.
Admin
Using foreign path formats, like Windows-specific UNC paths, as-is and expecting them to just work like in their native environments is misguided at best. It's like entering cmd.exe/batch-file commands in bash and wondering why you're getting a ton of errors.
The correct way is to mount the remote share, by way of samba (where the UNC path is used, though with forward slashes), and then the mount point is simply used.
However, In most modern file managers on Linux, like Dolphin, you can enter UNC paths as smb://host/share/path, optionally with user@ before the host part. Note that backslashes need to changed to the forward variety, just like when mounting.