Advertisement
T3RRYT3RR0R

batch Parameter Parser

Jan 15th, 2020
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.96 KB | None | 0 0
  1. @ECHO OFF
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3.  
  4. ::: Passing of Command / special Characters via unexpanded Variables. Only works for Shared Environments.
  5.  
  6. Set "Astring= A complex star c:\* -> A complex star"
  7.  
  8. CALL ParamTest.bat 3 4 2 1 2 3 4 5 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 Astring
  9.  
  10. ECHO HOME
  11. Pause
  12. exit
  13.  
  14. *******************************************
  15. ParamTest.bat
  16. *******************************************
  17.  
  18. @ECHO OFF
  19. SETLOCAL EnableDelayedExpansion
  20.  
  21. REM :: Used to define the Array Index values and Range
  22. set _I=0
  23.  
  24. REM :: The Core piece in recieving Large numbers of Parameters.
  25. REM :: Processes all Parameters. Tested to over 2500 Parameters.
  26.  
  27. FOR %%a in (%*) DO (
  28.     CALL Set /a _I+=1
  29.     CALL Set "arg[!_I!]=%%a"
  30.         IF DEFINED %%a (
  31.         CALL SET "arg[!_I!]=!%%a!"
  32.     )
  33. )
  34.  
  35. REM :: Loops through the Array to display Parameter Values.
  36.  
  37. FOR /L %%a in (1,1,!_I!) DO (
  38. ECHO !arg[%%a]!
  39. )
  40.  
  41. echo %_I% Arguements recieved.
  42. Pause
  43. GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement