DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Splitting/Joining URLs

04.29.2005
| 6138 views |
  • submit to reddit
        
File.dirname "http://foo.com/bar/stuff.html"
#=> "http://foo.com/bar"

File.basename "http://foo.com/bar/stuff.html"
#=> "stuff.html"

File.split "http://foo.com/bar/stuff.html"
#=> ["http://foo.com/bar", "stuff.html"]

File.join( File.dirname("http://foo.com/bar/doc.html"), "relative_link.html" )
# => "http://foo.com/bar/relative_link.html"

(Originally by Ilmari Heikkinen on the ruby-talk mailing list.)