Skip to content

Instantly share code, notes, and snippets.

Embed
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
setlocal
for %%d in (%~dp0.) do set Directory=%%~fd
echo Directory=%Directory%
for %%d in (%~dp0..) do set ParentDirectory=%%~fd
echo ParentDirectory=%ParentDirectory%
endlocal
@sobujbd

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
You can’t perform that action at this time.