I reduced the code to be brief:
@echo off
setlocal EnableDelayedExpansion
set /a n_tokens=2
for /f "tokens=!n_tokens! delims=\" %%s in ("Program\Executable") do (
echo %%s
)
pause > nul
I know that in this context it would not be necessary to use exclamations (!!) to expand the variable, but in the context I need it.
When using delayed expansion I get the error "tokens =! n_tokens! was unexpected", I would like to know what the problem is and some solution too.