I have a bat script and the first arg passed in is:
"C:\aaa^bbb\xxx^yyy.txt"
I wish to get the file and and containing dir (head):
set winhead=%~dp1
set winfile=%~nx1
echo winhead: %winhead%
echo winfile: %winfile%
Prints
winhead: 'C:\aaabbb\'
winfile: 'xxxyyy.txt'
I see the carets ^ where dropped. Okay I will just escape them:
set Pathin=%1
set Pathin=%Pathin:^=^^%
echo Pathin: %Pathin%
Prints
Pathin: "C:\aaa^^bbb\xxx^^yyy.txt"
Now to extract filename and head:
set winhead=%~dpPathin%
set winfile=%~nxPathin%
or
set winhead=%~dpPathin
set winfile=%~nxPathin
Does not perform the modifier, but just returns the literal string. After some research I discovered the modifiers can only be used on args, i.e. %1 in this case.
So is it a bug that the modifiers don't handle carets correctly? How does one extract parts of the full path for files one may have created in explorer (i.e. those which contain carets)?