« Who you are is not same as where you live | Main | Non-falsifiable propositions »

Equivalent of "which" in Windows Command Shell

I have always missed the which utility of Unix under Windows, which doesn't seem to have built-in equivalent. So, when I came across batch script parameter modifiers while browsing Windows shell scripting, I decided to write a Windows equivalent of which:


@echo off
rem --------------------------------------------------------
rem File: which.cmd
rem Description: Windows equivalent of Unix which command
rem Author: Pankaj Kumar
rem Copyright 2004 Pankaj Kumar. All Rights Reserved.
rem License: This software is available under GPL
rem ---------------------------------------------------------
setlocal
if "%1" == "" goto noArg

set fullpath=%~$PATH:1 if "%fullpath%" == "" goto notFound echo Found in PATH: %fullpath% goto end
:noArg echo No Argument specified goto end
:notFound echo Argument "%1" not found in PATH
:end endlocal

To use this command, either do a Copy-Paste of the above source code (but, beware of the formatting tags) or download which.cmd.

About

This page contains a single entry from the blog posted on November 27, 2004 11:24 AM.

The previous post in this blog was Who you are is not same as where you live.

The next post in this blog is Non-falsifiable propositions.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33