Search code examples
batch-filescriptingcommandwindows-server

Batch script command add/change number # in variable name


I have problem with "%_Link%%num%" its not working show up link after load from txt format. I think "%_Link%%num%" is wrong syntax function. but I know %_Link1%,%_Link2%,etc can work... but i want loop that will add/change number # in variable name like "_Link#" changeable number as #. here code below...

TEXT FORMAT (NOTEPAD):

http://www.google.com
http://www.nba.com
test3
test5
test6
test7

SCRIPT code:

@echo off
:: LOAD FILE
SetLocal EnableDelayedExpansion
Set n=
Set _InputFile=loadlink.txt
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
set /a i = 1
Set _Link!n!=%%I
Set /a num = 2
)


:loop1
CLS
echo.
echo %_Link%%num%
echo %i% seconds
start "" /b "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" %_Link%%num%
set /a i = i - 1
set /a num = num + 1
pause
GOTO loop1


:: pause

Solution

  • Try this:

    ECHO !_Link%n%!