BATCH_ Create libraries with valuable Batch subroutines
If you write some Batch subroutines that make common stuff like calculating the string length or testing for a number, you don't want to copy&paste these into each script that needs these. Be cool, there is a very easy solution how you can bundle all of your helper subroutines into one (or even more) files. Just copy them into an empty file, and add the following code at the very first line:
That jumps to the label you provided as the first parameter after shifting all remaining parameters one down leaving %0 as it is.
Let's say you saved that file as C:\Windows\lib.cmd. Now you can call any subroutine from another script by issuing
Remember to enable extensions and delayed variable expansion in each of your subroutines when needed - you cannot depend on the "frame" script's setting any more!
SHIFT /1 & GOTO %~1
That jumps to the label you provided as the first parameter after shifting all remaining parameters one down leaving %0 as it is.
Let's say you saved that file as C:\Windows\lib.cmd. Now you can call any subroutine from another script by issuing
CALL %SystemRoot%\lib.cmd :MY_SUBROUTINE param1 param2 ...
Remember to enable extensions and delayed variable expansion in each of your subroutines when needed - you cannot depend on the "frame" script's setting any more!
:MY_SUBROUTINE
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
... routine here ...
ENDLOCAL
GOTO :EOF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
... routine here ...
ENDLOCAL
GOTO :EOF
cypressor - 28. Nov, 22:24