Is there a way in a Windows batch script to return an absolute path from a value containing a filename and/or relative path?
Given:
I came across a similar need this morning: how to convert a relative path into an absolute path inside a Windows command script.
The following did the trick:
@echo off
set REL_PATH=..\..\
set ABS_PATH=
rem // Save current directory and change to target directory
pushd %REL_PATH%
rem // Save value of CD variable (current directory)
set ABS_PATH=%CD%
rem // Restore original directory
popd
echo Relative path: %REL_PATH%
echo Maps to path: %ABS_PATH%
Files See all other answers
Directories
With ..
being your relative path, and assuming you are currently in D:\Projects\EditorProject
:
cd .. & cd & cd EditorProject
(the relative path)
returns absolute path e.g.
D:\Projects