just escape your backlashes, or use forward slashes (/).
In my code I convert all paths tu unix style, work with them in that
form, and just before calling windows I convert them back. It makes
things much simpler. And in most cases even windows can handle forward
slashes.
File.join just cancatenates all strings with appropriate path delimiter.
And AFAIK ruby internally always uses / slash (e.g. puts dirname will
print c:/ruby/samples also on windows).
I think this also depends on what ruby you are using. If you are using
One Click installer Ruby for Windows, then your code should work as
you have it. If you are using cygwin, then it probably won’t work
correctly with the backslashes.
Based on the path you are referring to: C:\ruby, I assume you are
using One Click Ruby. However, in either event, forward slash should
work.
If you’re going to use blackslashes in a literal string you need to
double them because the backslash is an escape character. So, you
really need to do this:
p = Pathname.new(“C:\ruby\samples\myFile”)
Curt
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.