I have used a FOR
loop as a workaround in a batch script to pare a filename stored in a variable down to just its path:
FOR %%f IN ("%f%") DO (SET "o=%tmpdir%\%%~nxf" & SET "d=%%~dpf")
lib\JREPL.BAT "(SourcePath=\q)\.(\q)" "$1%d:$=$$%$2" /XSEQ /f "%f%" /o "%o%"
It seems as if the Parameter Extensions only work when you (ab)use the FOR
operator in this way. The following doesn't work:
REM "The following usage of the path operator in batch-parameter substitution is invalid"
ECHO lib\JREPL.BAT "(SourcePath=\q)\.(\q)" "$1%~dpf:$=$$%$2" /XSEQ /f "%f%" /o "%tmpdir%\%~nxf%"
Is this a true limitation of CMD (vs. e.g. PowerShell or a Unix shell), or am I just doing it wrong?