I have a list of 25 websites in a text file, each on an individual line, I would like to open them in random order via a batch file.
websites.txt
...
google.com
facebook.com
...
I know I need to use a for loop, but am not sure how to pull the website address from a random line. I thought of using...
for /f "tokens=%rannum%"
but all the websites would have to be on the same line and from my testing that did not work well. There would also need to be a way to make sure the same website is not opened twice.
What I have so far...
@echo off
set file=openweb.txt
set /a total_lines=1
for /f %%a in ('Type %_File%^|Find "" /v /c') Do Set /a total_lines=%%a
set /a start_count=0
set "found=found.txt"
if exist "%found%" del "%found%"
copy NUL found.txt
if %start_count% NEQ %total_lines% (
:run_again
REM Randomly select a number between 1-26
set /a random_number=%random% %% 26-1
REM Validation Random number was not used already
findstr /m "%random_number%" %found%
if %errorlevel%==0 (
echo already found
goto:run_again
)
REM Open each website. Wait 2sec between each.
for /f %%a in (websites.txt) do (
start iexplore %%a
@ping 127.0.0.1 -n 2 -w 1000 > nul
)
REM write out Random Number to the .txt
@echo %random_number%>>%found%
set /a start_count+=1
)
Any input on how to make this code better is welcome. Thank you