What I finished was as follows. As a rule, I do something, I thought that I would share ...
At the top of my batch file is the following code ...
Application:
::-------------------------------------------------------- :: Handle parameters ::-------------------------------------------------------- CALL:ChkSwitch bOverwrite "/OVERWRITE" %* CALL:ChkSwitch bMerge "/MERGED" %*
Then below (where I usually place all my functions) ...
Function:
::-------------------------------------------------------- :: ChkSwitch Function ::-------------------------------------------------------- :ChkSwitch <bRet> <sSwitch> <sParams> ( SETLOCAL EnableDelayedExpansion SET "switched=0" :ChkSwitchLoop IF "%~3"=="" GOTO ChkSwitchDone IF %~3==%~2 ( SET "switched=1" GOTO ChkSwitchDone ) SHIFT /3 GOTO ChkSwitchLoop :ChkSwitchDone ) ( ENDLOCAL SET "%~1=%switched%" EXIT /B )
Using it is simple. You simply call the function passed in the variable you want to change, or create, than the next pass you are looking for, and the last pass all the parameters from the script.
source share