@Echo off
rem #Doc: see SetEnvFirstFound_Test.cmd + SetEnvFirstFound_Help.txt
rem #Exa: Call SetEnvFirstFound UGII_BASE_DIR "C:\splm\NX2212" "C:\Program Files\Siemens\NX2212"
setlocal
set ResVar=%~1
set Res=
:Start
 shift
REM  Echo PNextValeu='%~1'
 if exist "%~1" set Res=%~1
 if defined Res goto :Done
 if "%~2" neq "" goto :Start
:Done
if defined Res Call :ParsAbs Res "%Res%"
endlocal&set %ResVar%=%Res%
goto :eof

:ParsAbs
 rem --#Doc: set abs path
 set ParAbs$T=%~dpnx2
 if "%ParAbs$T:~-1%" equ "\" set ParAbs$T=%ParAbs$T:~0,-1%
 set %1=%ParAbs$T%
 set ParAbs$T=
 goto :eof
