You can call other batch files via the call command
and pass parameters as well. Well, suppose you have a plethora of useful
functions but you don't want a batch file for each of them or copy them into all
batches that use them.
With a simple pattern you can concentrate them into one batch file. I've prepared this here, along with a bit of stuff you might need to do to ensure it's working:
The code above consists of a bit initialization code, namely the set target=%1 and shift to get
the label we want to jump to and return everything to normal for the following
code. The get_param_list is mainly there so we
have some weird code to look at and have a bit of debugging stuff in place for
testing. The rest are labels that mark the subroutines, ending with a goto :EOF each. The
batch itself is nothing more than some kind of switch statement, selecting the
function to execute with the first parameter.
lib.cmd):
Voilà, we got some kind of libraries or namespaces. If you want, you can nest them, I leave that as an exercise for the reader.