Advertisement
T3RRYT3RR0R

For Loop Cycle and Select lines in file to Retrieve

Apr 6th, 2020
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.91 KB | None | 0 0
  1. @Echo off & CD "%~dp0"
  2. TITLE %~n0 & Setlocal
  3.  
  4. %= Remark. Script for use on Windows 10 OS =%
  5. %= Script for validation and stroing Urls, with a loop to cycle through an array containing the Saved Urls =%
  6. %= Any time you can save a New url, you can type Load to selectively Cycle through the Array =%
  7.  
  8.     (Set LF=^
  9.  
  10.  
  11. %= NewLine variable to split set /p input line =%)
  12.  
  13. %= create blank batch file to store and Selectively retieve variables with =%
  14.  
  15.     If not Exist "inputURLlog.log" (Break>inputURLlog.log & Goto :main)
  16.     For %%A in ( "[N]ew" , "[L]oad")Do Echo.%%~A
  17.     Choice /N /C nl >nul
  18.     If errorlevel 2 (Goto :load)   
  19.     Goto :Main
  20.  
  21. :Input <VarName>
  22.     Set "variable=%~1"
  23.     Setlocal EnableDelayedExpansion
  24.  
  25. :Validate
  26. %= allow safe input of variable, test input, store for reuse. =%
  27.  
  28.     Echo(
  29.     Set /P "input=!variable!!LF!{> "
  30.     IF "!input!"=="" (
  31.         Echo(!variable! required.
  32.         Goto :Validate
  33.     )
  34.     If "!input!"=="" (Echo(!variable! required. & Goto :Validate)
  35.     IF /I "!input!"=="load" (Goto :load)
  36. %= Url Validation - Optional =%
  37.     (ping !input!)>nul || (Echo Invalid url & Endlocal & Goto :main)
  38.     ECHO(!input!>>inputURLlog.log
  39.     Endlocal
  40.     Exit /B
  41.    
  42. :main
  43.     Call :Input Url
  44.     Goto :main
  45.  
  46. :load
  47.     Setlocal EnableDelayedExpansion
  48.  
  49.     Set lines=0
  50.     For /f "Tokens=* Delims=" %%A in (inputURLlog.log) do (
  51.         Set /A lines+=1
  52.         Set "line[!lines!]=%%A"
  53.     )
  54.     Set "#=!lines!"
  55.     Echo %#%
  56. :extract
  57.  
  58.     For %%A in (!#!) do (
  59.     Cls
  60.     Echo(Url: !line[%%A]!
  61.     For %%B in ("[S]elect" , "[N]ext" "[L]ast")Do Echo.%%~B
  62.     Choice /N /C LNS /M ""
  63.     If "!errorlevel!"=="3" (Set "Url=!line[%%A]!" & Goto :Selected)
  64.     If "!errorlevel!"=="2" (IF not !#! GEQ !lines! (Set /A #+=1))
  65.     If "!errorlevel!"=="1" (IF not !#! LEQ 1 (Set /A #-=1))
  66.     )
  67.     Goto :extract
  68.    
  69. %= Demonstrate that variable has been reloaded =%
  70. :Selected
  71. Echo( Selected Url = !Url!
  72. Pause >nul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement