The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,650 other followers

which.bat (in case I don’t have CygWin on a system)

Posted by jpluimers on 2014/07/08

Small batch file that shows you the files on the path. It is a simple version that does not take into account built-in commands of cmd.exe, DOSKEY macros or PATHEXT environment variable: it just matches a name of an executable. Rob van der Woude has a complete which.bat (text version here) that does take into account all of the above. This is the poor man’s version:

@echo off
for %%f in (%1) do @echo. %%~$PATH:f
goto :eof

It uses this little trick from the FOR command:

%~$PATH:I Searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, this modifier expands to the empty string.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: