I suggest to put that on the Wiki - if it's not already there.

    robert

"Warren Brown" <wkb / airmail.net> schrieb im Newsbeitrag
news:002001c3762a$36d81260$803888cf / warrenpc...
> Hugh,
>
> > Has anyone come up with a method for converting
> > an absolute filesystem path into a relative
> > path, given the path to relate to?
>
>     Well, this doesn't handle Windows drive letters, but it handles the
> rest:
>
> # Convert the given absolute path into a path
> # relative to the second given absolute path.
> def relativepath(abspath,relativeto)
>   path = abspath.split(File::SEPARATOR)
>   rel  = relativeto.split(File::SEPARATOR)
>   while (path.length > 0) && (path.first == rel.first)
>     path.shift
>     rel.shift
>   end
>   ('..' + File::SEPARATOR) * (rel.length - 1) +
path.join(File::SEPARATOR)
> end
>
>     I hope this helps.
>
>     - Warren Brown
>
>