确定/解析 Windows 命令提示符中某个命令的文件路径/别名

确定/解析 Windows 命令提示符中某个命令的文件路径/别名

在 Windows 命令提示符中,如何找出某个命令输入将指向哪个文件路径(或别名)?具体来说是 Windows XP,其他版本的信息也值得赞赏!

在 Unix 系统上我只需使用:

$ which commandname
/a/commandname

或者:

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

我只是在寻找 Windows Shell(特别是 Win XP)中的等效项。


我从一个特定问题想到了这个一般性问题:我已经安装了 robocopy.exe(版本 026),但是命令行“robocopy”总是触发版本 010,我想确定此命令指向哪里,以便纠正这个错误。

答案1

较新的 Windows 发行版有该where命令。阅读这里了解更多信息。对于 Windows XP,您可以使用

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

正如我已经链接到的页面上的一个答案所描述的那样。

答案2

我发现这个简单的 Windows 批处理文件

@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

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`

相关内容