0

I am setting a number of variables using the for /f command.

setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /F "tokens=*" %%A in (target_list.txt) do (
    SET /A vidx=!vidx! + 1
    SET var!vidx!=%%A    
)
set var

Now that I have set them I need to be able to be able recall them in a loop and apply them to the following commands.

copy gateway%num%.bat \\%var1%\C$\WINDOWS\system32

psexec \\%var1%\ gateway%num%.bat

del \\%var1%\\C$\WINDOWS\system32\gateway%num%.bat

The reason I need them in a loop is because the number of variables will change periodically and I need it to be able to figure out how many it made in the previous command and then apply them in the second command. I don't want to have to copy this command over and over and only change (var1) to (var2) to (var3) etc.

Endoro
  • 37,015
  • 8
  • 50
  • 63
Samhut101
  • 5
  • 1
  • 3
  • I suggest you to use the standard array notation for your variables: `SET var[!vidx!]=%%A`. See: http://stackoverflow.com/questions/10544646/dir-output-into-bat-array/10569981#10569981 – Aacini Jun 03 '13 at 19:47

1 Answers1

2

try this:

for /l %%i in (1,1,%vidx%) do copy copy gateway%num%.bat \\!var%%i!\C$\WINDOWS\system32

for /l %%i in (1,1,%vidx%) do psexec \\!var%%i!\ gateway%num%.bat

for /l %%i in (1,1,%vidx%) do del \\!var%%i!\\C$\WINDOWS\system32\gateway%num%.bat
Endoro
  • 37,015
  • 8
  • 50
  • 63