ftnk.jp -> ~fumi -> ChangeLog -> 相対パスを求める
Prev / Next / ~fumi/ChangeLog

2004-01-30 / 相対パスを求める [Ruby]

pathname を使って次のように.

require 'pathname'

path = Pathname.new("/home/fumi/test.txt")
from = Pathname.new("/home/fumi/test/1")

relative_path = path.relative_path_from(from)


=> #<Pathname:../../test.txt>

Blog Widget by LinkWithin
blog comments powered by Disqus