Is there a way to resolve the ..
from an absolute file path in batch? For example, the following batch script should output C:\Users\xyz\other\abc.txt
:
REM Project dir is an absolute path, for example, C:\Users\xyz\project\
SET projectDir=%~1
REM Target file is a path relative to the project dir, for example, ..\other\abc.txt
SET target=%~2
REM Concatenate paths. This becomes C:\Users\xyz\project\..\other\abc.txt
SET absoluteTarget=%projectDir%%target%
SET absoluteTargetClean=...
echo %absoluteTargetClean%
The absoluteTarget
variable refers to an existing file.
I need the same for a directory instead of the file. Can you use the same way to achieve that?