4

in a.bat

if ... set a.b=1
...
set c=%%~!a.b!

echo %c% prints %~1, but I need contents of %~1. but set c=%~!a.b! results in "The following usage of the path operator in batch-parameter substitution is invalid: %~!a.b!." How to fix?

user490735
  • 755
  • 2
  • 9
  • 17

1 Answers1

4

You can't access the parameters with an evaluated expression directly,
as the percent expansion is one of the first phases of the parser.

But the CALL-trick can help you here.
Something like

set paramNo=1
call echo %%~%paramNo%

will expands first to call echo %%~1
and the CALL will restart the parser, so you get your desired result.

Community
  • 1
  • 1
jeb
  • 70,992
  • 15
  • 159
  • 202