4

How come this keep replacing the variable with each data from the loop instead of appending it?

set ipList=
for /F %%i in (ips.txt) do ( set ipList=%ipLis%,%%i )

2 Answers 2

10

It's true you need delayed expansion. Another way:

setlocal ENABLEDELAYEDEXPANSION
set ipList=
for /F %%i in (ips.txt) do ( set ipList=!ipList!,%%i )

Note the '!' instead of '%%'. Also, there was a typo in your question, I suppose it should be %%ipList%% instead of %%ipLis%% (a 't' is lacking).

Sign up to request clarification or add additional context in comments.

Comments

3

You need delayedexpansion or this technique:

set ipList=
for /F "delims=" %%i in (ips.txt) do call set "ipList=%%ipList%%,%%i"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.