How can I find out to which filepath (or alias) a certain command input will point to, in the Windows command prompt? Specifically Windows XP, info on other versions also appreciated!

On Unix systems I simply use:

$ which commandname


$ type -a commandname
commandname is aliased to `/b/commandname'
commandname is /a/commandname
commandname is /b/commandname

And I am simply looking for the equivalent in the Windows Shell (specifically Win XP).

I came to this general question, from a specific issue: I had installed robocopy.exe (version 026), but the command line "robocopy" always triggers version 010, and I would like to determine where this command points to, in order to correct this mistake.


Newer Windows distributions have the where command. Read here for more info. For Windows XP you can use

   c:\> for %i in (cmd.exe) do @echo.   %~$PATH:i

as one of the answers describes on the page I already linked to.


I found this simple Windows batch file:

@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 ---------------------------------------------------------
if "%1" == "" goto noArg

set fullpath=%~$PATH:1
if "%fullpath%" == "" goto notFound
echo Found in PATH: %fullpath%
goto end

echo No Argument specified
goto end

echo Argument "%1" not found in PATH


From help for:

%~$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, then this modifier expands to the  
               empty string`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.