Hi there,
as described here I created a huge amount of functions for my daily uses.
I use this functions in many scripts, so my question is if there is a smarter way then copy+paste the functions at the end of each single script.
Something like swapping all functions in a "functions.cmd" and include this "functions.cmd" in every script, so that I can access the functions.
Is something like that possible?
Thanks in Advance
Lorus
P.S. dostips.com is impressive and helped me very much so far
Swap Functions (in an include file)
Moderator: DosItHelp
Firstly, you can use
That will look for and call the label FUNCTION1
You can have lots of such functions, all with more meaningful names.
You quite possible already have this.
Unlike 'C' compilers, batch scripts do not support the #include MyFunctions.
Almost equivalent is to create Functions.cmd and start with GOTO %1,
and then append all your functions.
Then your "little scripts" will simply invoke
Note, you can choose to pass arguments to your function on the command line, or you can pass them via environmental variables.
Your function may be able to return values via environmental variables, but I vaguely remember some difficulties.
Alan
Code: Select all
CALL :FUNCTION1 arg2 arg3 etc
That will look for and call the label FUNCTION1
You can have lots of such functions, all with more meaningful names.
You quite possible already have this.
Unlike 'C' compilers, batch scripts do not support the #include MyFunctions.
Almost equivalent is to create Functions.cmd and start with GOTO %1,
and then append all your functions.
Then your "little scripts" will simply invoke
Code: Select all
CALL Functions.cmd FUNCTION1 arg2 arg3 etc
Note, you can choose to pass arguments to your function on the command line, or you can pass them via environmental variables.
Your function may be able to return values via environmental variables, but I vaguely remember some difficulties.
Alan