On Sunday 24 July 2005 11:59, Nigel Wilkinson wrote:
> Hi folks
>
> I have an absolute path to a specific file but I want to convert it to a
> path that's relative a specific directory. How can I do this?

Use the Pathname library (comes with Ruby):

irb(main):003:0> require 'pathname'
irb(main):004:0> p1 = Pathname.new("/home/me/foo/bar/baz")
=> #<Pathname:/home/me/foo/bar/baz>
irb(main):005:0> p2 = Pathname.new("/home/me")
=> #<Pathname:/home/me>
irb(main):006:0> p3 = p1.relative_path_from(p2)
=> #<Pathname:foo/bar/baz>

`ri Pathname' will show you all available methods.

HTH,
  Stefan