Posted By

jimfred on 11/27/08


Tagged

which


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

meetneps
Tyster
abumap


which command


 / Published in: DOS Batch
 

URL: http://www.rdpslides.com/publiclinks/FAQ00138.htm

This which.bat command works like Linux/bash 'which'

Save the Source as file which.bat and place it somewhere in the executable path.

Example usage: "which notepad.exe" results in "C:\WINDOWS\system32\notepad.exe". Note the .exe - 'which notepad' (without the .exe) results in "notepad not found in path"

See http://www.rdpslides.com/publiclinks/FAQ00138.htm for a description of the %~blah:1 syntax. The link describes the use of percent and tilde with environment variables.

This has a more extensive implementation: http://ss64.com/nt/which.cmd.txt

  1. @Set Which=%~$PATH:1
  2. @if "%Which%"=="" ( echo %1 not found in path ) else ( echo %Which% )

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Vordreller on March 21, 2009

This only seems to work for files located in the WINDOWS map.

Posted By: jimfred on May 13, 2010

It works for executables found in non-Windows directories listed in the PATH environment variable. For example, 'which.svn.exe' shows 'C:\Program Files\Subversion\bin\svn.exe' because, in this example, 'C:\Program Files\Subversion\bin' is listed in the PATH.

You need to login to post a comment.