How do I in a batch script find the full path to application XYZ if it is installed
Clarifications:
This is the closest I got. One drawback is that it works only for one drive per execution, but that could made more flexible. Another is the output, that always contains a //
between the path and the filename. But per definition thats a valid path.
@ECHO OFF
SET filename=autoexec.bat
FOR /R C:\ %%a IN (\) DO (
IF EXIST "%%a\%filename%" (
SET fullpath=%%a%filename%
GOTO break
)
)
:break
ECHO %fullpath%
Will deliver: C:\\autoexec.bat
EDIT:
For explanation, the for loop iterates through all directories starting at the given path (C:\) and check if the filename exists in that directory. If so, both variables are concatenated and stored in %fullpath% and the loop is terminated by a jump.