Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- 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"
- Set "UseErr=Echo/&Echo/Usage Error - Ensure command extensions and Delayed Expansion are enabled with: &Echo/Setlocal EnableExtensions EnableDelayedExpansion&Exit /B 1"
- If Not "!Comspec!"=="%Comspec%" (%UseErr%)
- (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
- If "%~1"=="" (%Usage:###=!FlNm! Usage:%) Else Call :GetArgs %*
- If Errorlevel 1 Exit /B 1
- If "!GRPNm!"=="" %Usage:###=/A:Groupname required%
- If "!#ORP#!"=="1" Echo/!SwParam!|findstr /RX [0-9]* > Nul 2> Nul
- If not "!SwParam!"=="" If Errorlevel 1 (%Usage:###=O:!SwParam! #Arg invalid. Only Integers accepted.%)
- If "!#ORP#!"=="1" Set "#!GRPNm!=0"
- If "!#%GRPNm%!"=="" Set "#!GRPNm!=0"
- If "%#FP#%"=="1" (
- If exist "!SwFParam!" (
- For /F "Delims=" %%G in (!SwFParam!)Do If Not "%%~G"=="" (
- For %%x in ("!GRPNm![!#%GRPNm%!]")Do (
- Setlocal DisableDelayedExpansion
- If "%#STDOut%"=="1" Echo/%%~x=%%~G
- Endlocal & Set "%%~x=%%G"
- )
- Set /A "#!GRPNm!+=1" > Nul
- )
- ) Else (%Usage:###=/F:!SwFParam! Invalid path%)
- )
- If not "!Inset!"=="" (
- For %%G in (!Inset!)Do (
- For %%x in ("%GRPNm%[!#%GRPNm%!]")Do (
- Setlocal DisableDelayedExpansion
- If "%#STDOut%"=="1" Echo/%%~x=%%~G
- Endlocal & Set "%%~x=%%~G"
- )
- If Not "!SubEL!"=="" Set "%%~G=!SubEl!"
- Set /A "#!GRPNm!+=1" > Nul
- )
- ) Else (
- If Not "%#FP#%"=="1" (
- For /F "Tokens=1,2 Delims==" %%I in ('Set %GRPNm%')Do Set "%%~I=" > Nul 2> Nul
- Set "#!GRPNm!=" > Nul 2> Nul
- )
- )
- Exit /B 0
- :GetArgs
- If "%~1" == "" Exit /B 0
- Set "Param=%~1"
- Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/D" > Nul 2> Nul && (Set "#STDOut=1"&Shift&Goto :GetArgs)
- Echo/"%~1"|"%__AppDir__%findstr.exe" /LC:"/A:" > Nul 2> Nul && (Set "GRPNm=!Param:*/A:=!"&(If "!Param:*/A:=!"=="" %Usage:###=/A:Groupname required%)&Shift&Goto :GetArgs)
- 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)
- 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)
- 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)
- Set Inset=!Inset! %1
- Shift&Goto :GetArgs
- Rem ::: Index count for each array GROUP stored in #GRPNm
Add Comment
Please, Sign In to add comment