Find the path used by the command line when calling an executable

纵然是瞬间 提交于 2019-12-02 12:16:23
@ECHO OFF
SETLOCAL
SET "pathd=%cd%;%path%"
SET "pathd=%pathd:)=^)%"
FOR /f "delims=" %%a IN ('echo %pathd:;=^&ECHO %') DO IF EXIST "%%~a\j*.exe" ECHO %%~a

GOTO :EOF

This should find - well, J*.exe files on the path (since I don't have ecd.exe) - just substitute ecd.exe for j*.exe.

It appends the current path to the current directoryname separated by ; then changes each ) to ^) in the resulting string.

The for operates on the concatenated enhanced path-string by substituting for ; with &echo - the carets before the ) on the previous line and the & in this line "escapes" the character, cause cmd to disregard the special meaning and treat it as an ordinary character.

This provides %%a as each individual path directory in turn; see whether the file (j*.exe) exists in the directory, and echo the directoryname if the file is found.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!