I am trying to write a batch file that exists in an arbitrary directory and will create a new directory two levels above it. For instance, the batch file here:
w:\src\project\scripts\setup.bat
would create:
w:\src\project.build
I can't seem to figure out how to expand a path. Here is what I am currently doing:
@set SCRIPT_DIR=%~dp0
@set ROOT_DIR=%SCRIPT_DIR%\..
echo ROOT DIR: %ROOT_DIR%
@set ROOT_DIR_NAME=%ROOT_DIR:~0,-1%
@echo ROOT DIR NAME: %ROOT_DIR_NAME%
And this produces:
ROOT DIR: w:\src\w_dev1\scripts\\..
ROOT DIR NAME: w:\src\w_dev1\scripts\\.
What I wanted to do, was get ROOT_DIR_NAME to be the directory itself (without the trailing slash). I know I could hack this and switch the -1 to account for the '..', but is there not a cleaner way to handle this?