@echo off :: Get drive+path of the running script (i.e. setenv.bat) set BASEDIR=%~f0 :: Get rid of the \bin\setenv.bat file name -> \bin call :GetParent BASEDIR "%BASEDIR%" :: Get rid of the \bin subfolder name -> call :GetParent BASEDIR "%BASEDIR%" :: Et voila, we got the actual base directory ... echo %BASEDIR% :: Skip any subroutines goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: SUBROUTINES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :GetParent :: Get the name of the variable we are working with setlocal ENABLEEXTENSIONS & set VAR_NAME=%1 :: Because we cut off the trailing backslash, the folder name looks like a file :: name and the preceding part appears as drive+path of that file ... set VAR_TEMPRET=%~dp2 :: Truncate the trailing backslash set VAR_TEMPRET=%VAR_TEMPRET:~0,-1% :: Pass back to global scope endlocal & set %VAR_NAME%=%VAR_TEMPRET% goto :EOF :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::