From: Emmanuel Touzery Date: 2002-11-30T07:48:23+09:00 Subject: Re: root directory On Friday 29 November 2002 22:41, Joel VanderWerf wrote: > Emmanuel Touzery wrote: > > I've been quick to write a Dir.up!() method (i was surprised it's not > > standard?), however i'm having trouble with the Dir.root?() one. > > There's File#dirname: > > irb(main):004:0> File.dirname('/usr/local') > "/usr" > > Dunno how well that works with drive letters, net shares, etc. on windows. I actually found File.split: irb(main):001:0> File.split("/home") ["/", "home"] irb(main):002:0> File.split("/") ["/", ""] encouraging. if file.split(dir)[1] == "" it could mean it's root. however i don't know how it behaves under windows, but in linux: irb(main):003:0> File.split("c:\test") [".", "c:\test"] irb(main):004:0> File.split("c:\\test") [".", "c:\\test"] :O/ emmanuel PS: for now i'm using the code i posted earlier. i could quickly check that it works under windows with standard pathnames (cmd.exe doesn't support UNC pathnames, didn't have the time to check for those). still, it's really ugly... :O((