Module: FileUtils

Defined in:
lib/FileUtils/where.rb,
lib/FileUtils/which.rb

Class Method Summary collapse

Class Method Details

.where(executable_sought) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/FileUtils/where.rb', line 20

def where(executable_sought)
  paths = ENV['PATH'].split(/:/)
  sought_paths = []
  paths.uniq.each do |path|
    Dir["#{path}/*"].each do |executable|
      if Platform::OS.windows?
        sought_paths << executable if File.basename_without_extname(executable) == File.basename_without_extname(executable_sought)
      else
        sought_paths << executable if File.basename(executable) == executable_sought
      end
    end
  end
  sought_paths.empty? ? nil : sought_paths
end

.which(executable_sought) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/FileUtils/which.rb', line 10

def which(executable_sought)
  if where_results = FileUtils.where(executable_sought)
    where_results[0]
  else
    nil
  end
end