Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Batch file to get parent directory without need of intermediate environment variables (so no need for setlocal as it is a one-liner)
echo batchfile=%0
echo full=%~f0
for %%d in (%~dp0.) do set Directory=%%~fd
echo Directory=%Directory%
for %%d in (%~dp0..) do set ParentDirectory=%%~fd
echo ParentDirectory=%ParentDirectory%

This comment has been minimized.

Copy link

@sobujbd sobujbd commented Aug 29, 2020

I perform this,

for %%I in (.) do set CurrDirName=%%~nxI
for %%I in (..) do set ParentDirName=%%~nxI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment