I want to use File.join()
for building paths in Ruby:
File.Join("Dir1", "Dir2", "Dir3")
Result is:
Dir1/Dir2/Dir3
I want File.join()
to uses File::ALT_SEPARATOR for doing this:
Dir1\Dir2\Dir3
How do I do this?
I want to use File.join()
for building paths in Ruby:
File.Join("Dir1", "Dir2", "Dir3")
Result is:
Dir1/Dir2/Dir3
I want File.join()
to uses File::ALT_SEPARATOR for doing this:
Dir1\Dir2\Dir3
How do I do this?
You could use
File.join('Dir1','Dir2').gsub(File::SEPARATOR,
File::ALT_SEPARATOR || File::SEPARATOR)
You can add this function to File
:
def File.join_alt(*fnames)
sep = File::ALT_SEPARATOR || File::SEPARATOR
fnames.map(&:to_s) # Anything with to_s
.join(sep) # Work on all platforms
end