T3RRYT3RR0R

Batch Array Defining Script

Aug 31st, 2020 (edited)
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.88 KB | None | 0 0
  1. @Echo off
  2.  Set "Usage=Echo/###&Echo/Call %~n0 "/A:Group Name" "element" "element..."&Echo/Call %~n0 "/A:Group Name" "/F:Filepath.ext"&Echo/Call %~n0 "/A:Group Name" REM : Clears the Array for the given Group Name&Echo/Call %~n0 "/A:Group Name" "element" "element..." "/O:3" REM : Overides Elements from the index supplied&Exit /B 1"
  3.  Set "UseErr=Echo/&Echo/Usage Error - Ensure command extensions and Delayed Expansion are enabled with: &Echo/Setlocal EnableExtensions EnableDelayedExpansion&Exit /B 1"
  4.  If Not "!Comspec!"=="%Comspec%" (%UseErr%)
  5.  (Set "SwParam="&Set "SwFParam="&Set "#ORP#=0"&Set "#FP#=0"&Set "Inset="&Set "#STDOut=0"&Set "GRPNm="&Set "!GRPNm!="&Set "SubEl="&Set "FlNm=%~n0") > Nul 2> Nul
  6.  If "%~1"=="" (%Usage:###=!FlNm! Usage:%) Else Call :GetArgs %*
  7.  If Errorlevel 1 Exit /B 1
  8.  If "!GRPNm!"=="" %Usage:###=/A:Groupname required%
  9.  If "!#ORP#!"=="1" Echo/!SwParam!|findstr /RX [0-9]* > Nul 2> Nul
  10.  If not "!SwParam!"=="" If Errorlevel 1 (%Usage:###=O:!SwParam! #Arg invalid. Only Integers accepted.%)
  11.  If "!#ORP#!"=="1" Set "#!GRPNm!=0"
  12.  If "!#%GRPNm%!"=="" Set "#!GRPNm!=0"
  13.  If "%#FP#%"=="1" (
  14.   If exist "!SwFParam!" (
  15.    For /F "Delims=" %%G in (!SwFParam!)Do If Not "%%~G"=="" (
  16.     For %%x in ("!GRPNm![!#%GRPNm%!]")Do (
  17.      Setlocal DisableDelayedExpansion
  18.      If "%#STDOut%"=="1" Echo/%%~x=%%~G
  19.      Endlocal & Set "%%~x=%%G"
  20.     )
  21.     Set /A "#!GRPNm!+=1" > Nul
  22.    )
  23.   ) Else (%Usage:###=/F:!SwFParam! Invalid path%)
  24.  )
  25.  If not "!Inset!"=="" (
  26.   For %%G in (!Inset!)Do (
  27.    For %%x in ("%GRPNm%[!#%GRPNm%!]")Do (
  28.     Setlocal DisableDelayedExpansion
  29.     If "%#STDOut%"=="1" Echo/%%~x=%%~G
  30.     Endlocal & Set "%%~x=%%~G"
  31.    )
  32.    If Not "!SubEL!"=="" Set "%%~G=!SubEl!"
  33.    Set /A "#!GRPNm!+=1" > Nul
  34.   )
  35.  ) Else (
  36.   If Not "%#FP#%"=="1" (
  37.    For /F "Tokens=1,2 Delims==" %%I in ('Set %GRPNm%')Do Set "%%~I=" > Nul 2> Nul
  38.    Set "#!GRPNm!=" > Nul 2> Nul
  39.   )
  40.  )
  41.  Exit /B 0
  42.  
  43.  :GetArgs
  44.  If "%~1" == "" Exit /B 0
  45.  Set "Param=%~1"
  46.  Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/D" > Nul 2> Nul && (Set "#STDOut=1"&Shift&Goto :GetArgs)
  47.  Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/A:" > Nul 2> Nul && (Set "GRPNm=!Param:*/A:=!"&(If "!Param:*/A:=!"=="" %Usage:###=/A:Groupname required%)&Shift&Goto :GetArgs)
  48.  Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/O:" > Nul 2> Nul && (Set "SwParam=!Param:*/O:=!"&(If Not "!Param:/O:=!"=="" (Set "#ORP#=1")Else %Usage:###=/O:#Arg not Supplied%)&Shift&Goto :GetArgs)
  49.  Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/F:" > Nul 2> Nul && (Set "SwFParam=!Param:*/F:=!"&(If Not "!Param:/F:=!"=="" (Set "#FP#=1")Else %Usage:###=/F:Filepath.ext not Supplied%)&Shift&Goto :GetArgs)
  50.  Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/S:" > Nul 2> Nul && (Set "SubEl=!Param:*/S:=!"&(If "!Param:/S:=!"=="" %Usage:###=/S:Sub Element not Supplied%)&Shift&Goto :GetArgs)
  51.  Set Inset=!Inset! %1
  52.  Shift&Goto :GetArgs
  53. Rem ::: Index count for each array GROUP stored in #GRPNm
  54.  
Add Comment
Please, Sign In to add comment