From: Emmanuel Touzery Date: 2002-11-30T20:14:16+09:00 Subject: Re: root directory Hello, On Saturday 30 November 2002 01:23, nobu.nokada@softhome.net wrote: > Emmanuel Touzery wrote: > > 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. > > No, File#split just returns File#dirname and File#basename, and > File#basename returns "" when the path is ended with "/". > > File.basename("/home/") => "" well, if we remove the final "/" it will be ok then? ok, what about this: # will return "." if you ask dirUp(root) def dirUp(path) # remove final "/" if there is one cleanPath = path.chomp(File::SEPARATOR) File.split(cleanPath)[0] end def root?(path) # remove final "/" if there is one cleanPath = path.chomp(File::SEPARATOR) File.split(cleanPath)[1] == "" end seems to work here under linux... emmanuel