You have 2 problems:
1) You are confusing FOR variables with environment variables. A batch FOR variable name is always a single character, and it is access via 2 percents prior to the name: %%c
. A FOR variable value cannot be changed with SET.
An environment variable name can contain multiple characters, though it can be a single character, and it is accessed by enclosing the name in percents: %var%
. Exclamation points can be used if you want delayed expansion: !var!
. An environment variable value is set with SET.
2) The CALL trick to access environment variable values that were set within a parenthesized code block is used at expansion time, not when you are setting the value.
I believe mousio provided provided the best answer; I always use delayed expansion like in that answer. But it is possible to do what you want without delayed expansion by properly using an environment variable and the CALL trick.
@echo off
for /f "tokens=1-3 delims=," %%a in (Puck.csv) do (
echo Hello No Hockey>%%a.txt
echo #:A %%a>>%%a.txt
echo #:B %%b>>%%a.txt
set C=%%c
if /i %%c gtr 10 set C=1
call echo #:C %%C%%>>%%a.txt
)
Note that it is critical that the case of the FOR variable is different than the environment variable. FOR variables are case sensitive, environment variables are not. If you use c
for both, then the parser will treat %%c%%
as the FOR variable followed by a percent - not what you want.