Version 3 of which

Updated 2004-03-20 18:54:55

AJB which - A utility that almost works like the Unix which, but it works in Windows as well. The difference: if it doesn't find the file, it just returns null. I did this because it makes it easier to work with in programs. Unix returns something like: which: no "filename" in /bin /usr/bin /usr/local/bin ... Also, if anyone has a Mac and knows what delimeter is used in ::env(PATH), could you please post the line to add to the opening switch statement so that this can be truly cross-platform. Thanks.

 proc which {filename} {
  switch $::tcl_platform(platform) {
    windows {set dirlist [split $::env(PATH) \;]}
    default {set dirlist [split $::env(PATH) :]}
  }
  foreach dir $dirlist {
    set fullname [file join $dir $filename]
    if {[file exists $fullname] && [file executable $fullname]} {
      return $fullname
    }
  }
  return ""
 }