The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
The Pathname crusade continues

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
The Pathname crusade continues Posted: May 20, 2005 8:48 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: The Pathname crusade continues
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Just when I thought I was nearly ready to present a revamped Pathname class, I've hit a snag. It rests with the concept of a path root.

My oh-so-clever original implementation just used File.dirname until it eventually worked down to the smallest string component. That would be the root. It works, too. So, the root of "/foo/bar" is "/" while the root of "C:\foo\bar" is "C:\". That's great, except for the part where it doesn't work on UNC paths.

You see, if you're on Windows and have a mapped drive, it looks something like "\\foo\bar\baz". Go ahead, take a guess at what the root of that path is. Did you guess "\\"? Or "\\foo"? You guessed wrong. The root of that path is "\\foo\bar".

So, how does one go about creating a sane way of determining the root directory in a cross platform way? The answer is, you don't, at least not without jumping through a lot of potentially flawed hoops. I'd rather avoid that. Fortunately, there *is* a solution in the Win32 API which is kind enough to provide some path name handling methods. The method in particular is called PathStripToRoot. It has some other handy methods I plan to use as well.

In other news, I'm glad to see that my revamped version of Pathname#cleanpath actually matches what the PathCanonicalize method does. The current implementation doesn't make any sense to me. So, that's a bit of ammo for me for anyone who complains. :)

Read: The Pathname crusade continues

Topic: 30 Quicksilver and Tiger Voiceover Previous Topic   Next Topic Topic: 2e Rails meetup in San Francisco

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use