Batch snippet for parsing arguments with parameters

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Batch snippet for parsing arguments with parameters

Post by Mistrel »

This is a batch snippet that can be used for parsing arguments with their own parameters. This isn't a PureBasic snippet but it's useful for anyone who likes to create batch utils for command line compiling and automation.

Code: Select all

REM Real batch arguments
REM Call :ProcessArgs

REM Fake batch arguments
Call :ProcessArgs /Switch1 /Switch2 "Param1" /Switch3

Rem
Rem ProcessArgs subroutine
Rem
:ProcessArgs
    Set Arg=0
    :ProcessArgs_Loop
    If /I [%1]==[/Switch2] (
        Echo %Arg% %1 %~2 & REM Strip quotes from param
        Shift & REM Additional shift for switch param
    ) Else (
        If Not [%1]==[] (
            Echo %Arg% %~1
        )
    )
    Set /A Arg+=1
    Shift
    
    If Not [%1]==[] GoTo :ProcessArgs_Loop
GoTo :EOF