0
텍스트 파일에 25 개의 웹 사이트 목록이 있는데, 각 줄마다 개별적으로 배치 파일을 통해 임의의 순서로 엽니 다.텍스트 파일에서 임의의 줄 선택 및 실행
websites.txt
...
google.com
facebook.com
...
는 내가 루프를 사용할 필요가 알고 있지만, 임의의 줄에서 웹 사이트 주소를 당겨하는 방법을 잘 모르겠습니다. 나는 사용을 생각했다 ...
for /f "tokens=%rannum%"
그러나 모든 웹 사이트는 똑같은 라인에 있고 내 테스트에서 제대로 작동하지 않아야했다. 또한 동일한 웹 사이트가 두 번 열리지 않도록하는 방법이 필요합니다.
내가 지금까지 무엇을 가지고...
@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
)
이 코드는 더 나은 만드는 방법에 대한 입력을 환영합니다. 당신은
... 을에서 : http://stackoverflow.com/questions/13343144/random-line-of-text-ussing-batch – user4241682