I just had to work on some code that ran into trouble, because Ruby
uses “/” to separate folders, but the path was being passed to a
separate command (using system) that expected Window’s paths to use
“”.
I told my collegues that instead of using File.join, they should just
use + “\” +
But this got me to wondering what the point of File.join was if you
couldn’t trust it to construct paths correctly (unless you were sure
that the path was only going to be used by other ruby commands).
Is there a rationale? Is there a different library that i should be
using instead?
I told my collegues that instead of using File.join, they should just
use + “\” +
But this got me to wondering what the point of File.join was if you
couldn’t trust it to construct paths correctly (unless you were sure
that the path was only going to be used by other ruby commands).
Is there a rationale? Is there a different library that i should be
using instead?
I told my collegues that instead of using File.join, they should just
use + “\” +
I’d probably rather use [“foo”, “bar”].join File::SEPARATOR (if that’s
set to \ on Windows).
But this got me to wondering what the point of File.join was if you
couldn’t trust it to construct paths correctly (unless you were sure
that the path was only going to be used by other ruby commands).
Exactly. File.join produces paths that Ruby can correctly use. That’s
the rationale.
Is there a rationale? Is there a different library that i should be
using instead?
Well, you could do path.tr ‘/’, ‘\’ before passing the path to some
other process.
No, Windows and DOS have always supported ‘/’. But some programs (in
particular, COMMAND.COM and CMD.EXE) have a problem because of an
ancient need to be compatible with DOS 1.0.