I'm writting a batch file and I want to move some files from root path to cd .. root.
I use %~dp0 to find the root path.
Whats the best method to go back one step from root path?
Thanks a lot
I'm writting a batch file and I want to move some files from root path to cd .. root.
I use %~dp0 to find the root path.
Whats the best method to go back one step from root path?
Thanks a lot
%~dp0
points to the parent directory of the current batch file (including a trailing \
), %~dp0..
therefore points to the grand-parent directory of the batch file.
You can use a for
loop and the ~f
modifier of its variable reference (%%I
) to resolve the path:
for %%I in ("%~dp0..") do echo/%%~fI
you are almost there, just use %~dp0..
or if you want it fully resolved, use this trick
@echo off
call :resolve "%~dp0.."
goto :eof
:resolve
echo %~f1
goto :eof
for an explanation, see this SO answer https://stackoverflow.com/a/15568171/30447