‘whereis’ for DOS

This useful .cmd script will find the location of an executable on your %PATH%. It’s the Windows equivalent of the whereis command in linux.

[whereis.cmd]

@echo off
setlocal
SET MYPATHCOPY=%PATH%
SET SEARCHFOR=%1

:search
for /f "delims=; tokens=1,2*" %%p in ("%MYPATHCOPY%") do (
   if EXIST "%%~p\%SEARCHFOR%*" echo %%~p
   SET MYPATHCOPY=%%~q;%%~r
)

if "%MYPATHCOPY%"==";" goto done;
goto search;

:done
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s