此题答案:
@echo off
FOR /F %%i IN ("%1") DO if "%%~$PATH:i" NEQ "" echo %%i, "%%~$PATH:i"
这个是我平时用的
@echo off
if "%1"=="" (
echo Usage %0 command
echo For example: %0 cmd
call %0 cmd
) else (
rem to add other kind of commands, copy the line below and edit the ext-name.
FOR /F %%i IN ("%1.com") DO if "%%~$PATH:i" NEQ "" echo %%i, "%%~$PATH:i"
FOR /F %%i IN ("%1.exe") DO if "%%~$PATH:i" NEQ "" echo %%i, "%%~$PATH:i"
FOR /F %%i IN ("%1.bat") DO if "%%~$PATH:i" NEQ "" echo %%i, "%%~$PATH:i"
FOR /F %%i IN ("%1.cmd") DO if "%%~$PATH:i" NEQ "" echo %%i, "%%~$PATH:i"
)
[code=BatchFile]
@echo off
title 查询文件所在位置 - 佛爱我羊 [2008]
cls
for /f "tokens=*" %%a in ("%1") do (call :result %%~nxa)
echo.
echo 查询完毕,按任意键退出...&pause>nul 2>nul
goto end
:result
echo %1存在于下列路径中
echo ========================================
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist %%i:\ (
dir %%i:\ /b /s /a-d|findstr /i /c:"%1"
)
)
[code=BatchFile]
@echo off
cls
for /f "tokens=*" %%a in ("%1") do (call :result "%%~na" "%%~xa")
echo.&echo.&echo 查询完毕,按任意键退出&pause>nul 2>nul
exit
:result
set showfn=%1%2
set showfn=%showfn:"=%
set fext=%2
set fext=%fext:.=%
echo %showfn%存在于下列路径:&echo ============================================
for /f "tokens=2* delims==" %%i in ('wmic path cim_logicalFile where 'filename^=%1 and Extension^=%fext%' get name /value') do (echo %%i)
[/code]