I never thought to test that before, but I suppose it makes some amount of sense. The parser is getting confused by the %~$PATH:I
FOR /? wrote:
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
I posted an analysis of valid characters for use as FOR variables
on StatckOverflow - see the Addendum. I've updated that answer with the info about %%~$
. I gave you a credit in a comment after the answer.
Somewhere on DosTips I started a discussion thread about FOR variables, but I can't find it