There are two ways to obtain a reference to a file/folder: arguments to batch files and for
command. This second option is what we will use here. As it is not clear what parent do you need, let's see how to obtain each
1 - Get parent of current active directory
for %%a in (..) do echo %%~fa
get a reference to the parent of the current active folder inside the for
replaceable parameter %%a
and once we have the reference, get the full path to it
2 - Get parent of the folder holding the batch file
for %%a in ("%~dp0.") do echo %%~dpa
same idea. %0
is a reference to the current batch file, so %~dp0
is the drive and path where the batch file is stored. This value ends in a backslash, so, to get a reference to the folder an aditional dot is added. Once we have the reference to the folder holding the batch file in %%a
, %%~dpa
will return the drive and path where the element referenced in %%a
is stored. As %%a
is the folder holding the batch file, %%~dpa
is the parent, the folder where is stored the folder with the batch.