Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created August 17, 2013 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/6257059 to your computer and use it in GitHub Desktop.
Save jpluimers/6257059 to your computer and use it in GitHub Desktop.
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
Copy link

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