Perhaps the simplest approach is to abandon the goal of putting multiple routines in one module.bat. Instead you can create a batFunctions folder to house a separate bat file for each routine. Then you simply need to make sure the batFunctions path is in in your PATH. Any batch script can then simply CALL any function within that folder (without the colon prefix of course).
You could configure your machine to always have batFunctions in your PATH.
An alternative that would be very similar to an #include directive would be to have your parent batch script modify PATH (after a SETLOCAL) and put the batFunctions path in the front.
someScript.bat
Code: Select all
@echo off
setlocal
path c:\batFunctions;%path%
...
It is possible for the above to fail if your PATH includes any unquoted poison characters (unlikely, but possible). Switching to delayed expansion should eliminate that problem.
Code: Select all
@echo off
setlocal enableDelayedExpansion
path c:\batFunctions;!path!
...
You don't want to forget the SETLOCAL, else your PATH will grow each time you run your script. The SETLOCAL makes it more difficult to have a batch script define environment variables that survive the ENDLOCAL. But there is loads of information on DosTips describing techniques to preserve values after ENDLOCAL.
Dave Benham