Method: File.which

Defined in:
lib/rwd/ftools.rb

.which(file) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rwd/ftools.rb', line 149

def self.which(file)
  res	= nil

  if windows?
    file	= file.gsub(/\.exe$/i, "") + ".exe"
    sep		= ";"
  else
    sep		= ":"
  end

  catch :stop do
    ENV["PATH"].split(/#{sep}/).reverse.each do |d|
      if File.directory?(d)
        Dir.new(d).each do |e|
           if e.downcase == file.downcase
             res	= File.expand_path(e, d)
             throw :stop
          end
        end
      end
    end
  end

  res
end