I have a simple bat script as follows:
for %%f in (DW_*.csv) do (
echo f is.....: %%f
set nam=%%f
echo nam is ...: %nam%
)
The problem is the variable I am calling nam IS being set, but is NOT being echo'ed properly (it seems like it does NOT actually get set)
Can someone help me?
ps: I already tried enabling delayed expansion, but I still do not get expected results (see red arrow)
Ok the solution was indeed related to delayed expansion. Since this appears to be a common issue, I will leave this semi-duplicated post online with the following note: delayed expansion uses this syntax for referencing !variables! not this %syntax%
So this code worked and provides expected results:
setlocal enabledelayedexpansion
for %%f in (DW_*.csv) do (
echo f is.....: %%f
set nam=%%f
echo nam is ...: !nam!
)