From: "Barnett, Aaron" Date: 2001-08-30T23:36:59+09:00 Subject: [ruby-talk:20581] RE: Relative path i havnt impressed myself with the elegance of this solution, but it works. def rel_path(a, b) new_path = '' a = a.split('/') b = b.split('/') raise "windows sucks" if a[0] =~ /^\w\:$/ and a[0] != b[0] while a[0] == b[0] a.shift b.shift end a.size.times { new_path += '../' } b.each { |dir| new_path += dir + '/' } new_path end -----Original Message----- From: Gardian, Milan [mailto:Milan.Gardian@LEIBINGER.com] Sent: Thursday, August 30, 2001 9:41 AM To: ruby-talk@ruby-lang.org Subject: [ruby-talk:20580] Relative path Hello, what is the shortest & quickest way of finding a relative path between path1 and path2 in Ruby? (either universal or Win32 platform-specific)... E.g.: ----- path1 = "c:/temp/foo" path2 = "c:/temp/foo/dir/another_dir" path3 = "c:/special_dir" path4 = "d:/dir" rel_path(path1, path2) -> "dir/another_dir" rel_path(path2, path1) -> "../.." rel_path(path2, path3) -> "../../../special_dir" rel_path(path1, path4) -> Exception - not possible ----- Thank you for your help! Cheers, Milan