Other bug of %~f0 that I found here:
viewtopic.php?t=5057#p29705
Is related when you change the current directory inside the script, the result is different if you called your script with quotes.
This is script is located in C:\dev\test2.cmd
Code: Select all
@echo off
Setlocal EnableExtensions
E:
Echo E:
echo %%~f0 = %~f0
echo %%~dpf0 = %~dpf0
Result:
Code: Select all
C:\dev>test2.cmd
E:
%~f0 = C:\dev\test2.cmd
%~dpf0 = C:\dev\test2.cmd
C:\dev>"test2.cmd"
E:
%~f0 = E:\test2.cmd
%~dpf0 = E:\test2.cmd
C:\dev>
As you can see run test2.cmd and "test2.cmd" produce different result.
%~dpf0 not solve the problem, and also have non sense.
According to the documentation:
%~f Expand %1 to a Fully qualified path name.
%~d Expand %1 to a Drive letter only.
%~p Expand %1 to a Path only
Thus %~dpf is like concatenate: drive letter, path only, and fully qualified path. Fully qualified path also include drive letter and path. Thus, why try concatenate it again? Seems that cmd detect this nonses and internally convert %~dpf to %~f