Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- @Echo off & CD "%~dp0" & TITLE Extractor %~n0 & Setlocal & REM Extractor by T3RRY :::
- ::: :::
- ::: - Program demonstrating the following principles: :::
- ::: - Multiline display via Caret with LF variable and Delayed Expansion :::
- ::: - Same Line Mulitocolor Display using Ascii Escape Code :::
- ::: - Safe input with Validation using Set /P, Doublequoting, Delayed Expansion and Conditional Checks :::
- ::: - Loading of contents of text files into array for user selection and use by a Choice 'Scroll' Function. :::
- ::: :::
- ::: - The techniques in this demo have practical application for scripts which require user input to be :::
- ::: stored and selectively retrieved in future executions of the script. :::
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- (Set LF=^
- %= NewLine variable to split set /p input line =%)
- ::: / Creates variable /AE = Ascii-27 escape code.
- ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
- ::: - https://stackoverflow.com/a/34923514/12343998
- :::
- ::: - /AE can be used with and without DelayedExpansion.
- Setlocal
- For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
- Endlocal
- Set "/AE=%%a"
- )
- ::: \
- ::: - create blank batch file to store and Selectively retieve variables with
- :Menu
- CLS
- If not Exist "inputURLlog.log" (Break>inputURLlog.log & Goto :main)
- For %%A in ( "%/AE%[36m[%/AE%[35mN%/AE%[36m]ew" , "[%/AE%[35mL%/AE%[36m]oad%/AE%[0m")Do Echo.%%~A
- Choice /N /C nl >nul
- If "%errorlevel%" == "2" (Goto :load)
- Goto :Main
- :Input <VarName>
- Set "variable=%~1"
- Setlocal EnableDelayedExpansion
- :Validate
- ::: - allow input of variable, test input, store for reuse.
- Echo(%/AE%[35m
- Set /P "input=!variable!!LF!%/AE%[36m{> %/AE%[33m"
- If "!input!"=="" (
- Echo.%/AE%[31m!variable! required.!LF!%/AE%[33m{%/AE%[37m e exit q quit c close %/AE%[33m} To Exit!LF!%/AE%[33m{%/AE%[37m m menu b back r return %/AE%[33m} For previous Menu!LF!%/AE%[33m{%/AE%[37m l load o open s start %/AE%[33m} To select and start an url
- Pause > Nul & Goto :Validate)
- For %%I in (e exit q quit c close) do IF /I "!input!"=="%%I" (EXIT)
- For %%I in (m menu b back r return) do IF /I "!input!"=="%%I" (Goto :menu)
- For %%I in (l load o open s start) do IF /I "!input!"=="%%I" (Goto :load)
- IF /I "!input!"=="load" (Goto :load)
- ::: - Url Validation - Optional
- (ping !input!) > Nul || (Echo Url not valid & Endlocal & Goto :main)
- ECHO(!input!>> "inputURLlog.log"
- Endlocal
- Exit /B
- :main
- Call :Input Url
- Goto :main
- :load
- Setlocal EnableDelayedExpansion
- Set lines=0
- For /f "Tokens=* Delims=" %%A in (inputURLlog.log) do (
- Set /A lines+=1
- Set "line[!lines!]=%%A"
- )
- REM Set "#=%lines%" & REM start from newest entry
- Set "#=1" & REM start from oldest entry
- :extract
- For %%A in (!#!) do (
- Cls
- Title Option %%A of !lines!
- Echo(%/AE%[32mUrl: %/AE%[33m!line[%%A]!
- For %%B in ("%/AE%[36m[%/AE%[35mS%/AE%[36m]tart" , "[%/AE%[35mN%/AE%[36m]ext" "[%/AE%[35mL%/AE%[36m]ast" "[%/AE%[35mM%/AE%[36m]enu%/AE%[0m")Do Echo.%%~B
- Choice /N /C LNSM
- If "!errorlevel!"=="4" (Endlocal & Goto :Menu)
- If "!errorlevel!"=="3" (Set "Url=!line[%%A]!" & Goto :Selected)
- If "!errorlevel!"=="2" (IF not !#! GEQ !lines! (Set /A #+=1) Else (Set "#=1"))
- If "!errorlevel!"=="1" (IF not !#! LEQ 1 (Set /A #-=1) Else (Set "#=%lines%"))
- )
- Goto :extract
- ::: - Demonstrate that variable has been reloaded
- :Selected
- start "" !Url!
- Pause >nul
- Endlocal
- GOTO :load
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement