Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to get filename, dirname, and basename in bat?
set filepath="C:\some path\having spaces.txt"
for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi"
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
echo %dirname%
echo %filename%
echo %basename%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment