From: Trans Date: 2006-08-15T00:10:14+09:00 Subject: Re: sh command that ascends dir tree for executable Jeffrey Schwab wrote: > Trans wrote: > > Jeffrey Schwab wrote: > >> Not quite, but it's a great idea! You might want to sit down for this one: > >> > >> C:\>ruby -rpathname -e 'puts Pathname.getwd' > >> C:/ > >> > >> C:\>ruby -rpathname -e 'puts Pathname.getwd.parent' > >> C:/.. > >> > >> Could you live with something like this, or are the regex/string > >> manipulation/punctuation just too ugly? > >> > >> file = ARGV.shift > >> > >> Dir.chdir('..') until File.executable?(file) or > >> Dir.getwd =~ /^(?:\w:)?[\/\.]*$/ > >> > >> puts Dir.getwd.gsub(/\/$/, '') + '/' + file if File.executable?(file) > > > > Guess I don't have much of choice. Pretty sad choice though. I can't > > beleive there's not a cleaner solution. > > Well, you could always write your own, more WinFriendly module, in which > path.root? and friends worked more like one would expect. It's more > code up front, but it only has to be written once. I'm not going to bother with a whole module. It's been done before. Actually I'm suprised that Daniel Berger's work on Pathname2 hasn't found it's way back to imporving Ruby's built in Pathname class. Appearently he put a lot of effort into better Windows support. Think I'll just write FileTest.root?( dir ) and make due. T.