Version 0 of which

Updated 2004-03-20 16:16:45

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 make it easier to work with in programs. Unix return 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 truely 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 ""
 }