![确定/解析 Windows 命令提示符中某个命令的文件路径/别名](https://linux22.com/image/1264679/%E7%A1%AE%E5%AE%9A%2F%E8%A7%A3%E6%9E%90%20Windows%20%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E7%AC%A6%E4%B8%AD%E6%9F%90%E4%B8%AA%E5%91%BD%E4%BB%A4%E7%9A%84%E6%96%87%E4%BB%B6%E8%B7%AF%E5%BE%84%2F%E5%88%AB%E5%90%8D.png)
在 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
@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`