# 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 + '.'); }
}());