PoshCode Archive  Artifact Content

Artifact 26d4f62273750529f0ab4549ffce7b909340269996e4f56f54e92f0e153e7be4:

  • File which-js.ps1 — part of check-in [2d2e7d476b] at 2018-06-10 13:50:12 on branch trunk — Looks for a file into PATH variable. (user: greg zakharov size: 878)

# encoding: ascii
# api: powershell
# title: which.js
# description: Looks for a file into PATH variable.
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# x-poshcode-id: 5117
# x-archived: 2014-08-29T23:29:35
# x-published: 2014-04-24T15:47:00
#
#
(function() {
  var fso = new ActiveXObject('Scripting.FileSystemObject'),
      wsh = new ActiveXObject('WScript.Shell'),
      lst = function(e) {
        return wsh.ExpandEnvironmentStrings(e).split(';');
      },
      dir = lst('%PATH%'),
      ext = lst('%PATHEXT%;.DLL'),
      itm, i, j;
  
  try {
    for (i in dir) {
      for (j in ext) {
        itm = dir[i] + '\\' + WScript.Arguments.Unnamed(0) + ext[j].toLowerCase();
        if (fso.FileExists(itm)) WScript.echo(itm);
      }
    }
  }
  catch (e) { WScript.echo(e.name + ': ' + e.message + '.'); }
}());