Why the following failure of %~d0 to return the batch file\'s drive letter S: when CALL quotes the name of the batch file?
S:\\!DJ DAP>type test.b
Like dbenham: Fascinating!
I suppose it's a feature of cmd.exe.
Quotes aren't stripped from %0
in the main batch context.
But they are all stripped by a call to a subroutine.
This can be realized when more than two quotes are used, only one quote from each side will be removed when the %0
is expanded.
ParamTest.bat
@echo off
cls
setlocal
d:
echo Main %%0: %~0, %~f0
echo Main %%1: %~1, %~f1
call :func %1
exit /b
:func
echo Func %%0: %~0, %~f0
echo Func %%1: %~1, %~f1
exit /b
Output for: """"PARAM"test.BAT" ""paramTEST.bAt""
Main %0: """PARAM"test.BAT, D:\"""PARAM"test.BAT Main %1: "paramTEST.bAt", D:\"paramTEST.bAt" Func %0: :func, C:\temp\ParamTest.bat Func %1: "paramTEST.bAt", D:\"paramTEST.bAt"
And %0
seems to save the related directory, as you get different results for %~f0
and %~f1
even when the content seems to be equal.
But perhaps the path is just prefixed to %0
.
Output for: PARAMtest.BAT paramTEST.bAt
Main %0: PARAMtest.BAT, C:\temp\ParamTest.bat Main %1: paramTEST.bAt, D:\paramTEST.bAt Func %0: :func, C:\temp\ParamTest.bat Func %1: paramTEST.bAt, D:\paramTEST.bAt