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%
I have awed this for crap many times before, now I have it here for the future.