Hi,
Why bothrer and remember which slash to use ? Ruby does it for you.
Here is my approach:
require 'pathname'
p = Pathname.new(File.join('c:', 'ruby', 'samples', 'myfile'))
=> #<Pathname:c:/ruby/samples/myfile>
puts p.dirname
=>c:/ruby/samples
puts p.basename
=> myfile
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).
--
Martins
On 7/28/06, N Okia <wrecklass1@gmail.com> wrote:
> 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.
>
>