I have following code snippet
setlocal enableextensions enabledelayedexpansion
set b=123
for %%f in (.\input\*.mgc) do (
set "b=%%~nf"
echo %b%
)
I am expecting it to output file name with no extension but I always get "123". I concluded it has something with late expansion but not quite sure where the problem comes from. I have also tried with echo !b! but in that situation it outputs only "!b!"
echo !b!echo !b!displays a literal!b!- either you didn't usesetlocal enabledelayedexpansionor the one file in the input directory is called!b!.mgc. Those are literally the only two ways your output is possible. Ifbwasn't being set and delayed expansion was actually on like you claim it is, you'd see the errorECHO is off.