Prev / Next

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

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>


comments powered by Disqus