In your AG14InstallDir.bat you use setx AG14InstallDir "C:\SOL\Java14\\" The doublequotes "around" make it necessary to unescape the last \ with \ Changing the last \ into a space character as below works too. setx AG14InstallDir "C:\SOL\Java14\ " If you do not use the doublequotes then the following works nicely. setx AG14InstallDir C:\SOL\Java14\ (doublequotes around a path are for example needed if there is a space character somewhere in the string.) I combined AG14InstallDir.bat and AG14Version.bat into one batch file and changed your hardcoding of the path and the version name into code that is independent from where you install AGL The content of the batch file reads like this: @echo off cd .. rem the files you work on are one directory up to where this batch file is placed. setlocal set /A counter=0 for %%i in (*.jar) do set /a counter+=1 if %counter% GTR 0 goto go-on if %counter% equ 0 echo no AGL file found. pause exit /b :go-on rem file with youngest datum .jar will be chosen FOR /F "delims=" %%a IN ('DIR "*.jar*" /A-D /B /O:D') DO SET "name=%%~na" rem /a-d show only files; not directories rem /b get only file-names; no attributes etc. rem /o:d get filenames with yougest entries first setx AG14InstallDir %__cd__% & echo installed in %__cd__% rem %__cd__% gets current path including closing \ setx JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8 setx AG14Version "%name% echo version %name% will be used. endlocal pause