Class: Libruby::FileUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/libruby/file_utils.rb

Class Method Summary collapse

Class Method Details

.which(cmd) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/libruby/file_utils.rb', line 3

def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  return nil
end