Batch Function Overview
What are they?
A batch function is a block of batch code that can be called by a batch file, optionally with a number of parameters. The function performs its task without unintentionally modifying variables outside of its own scope, and then returns control to the statement following the one that called the function.
Why use them?
The primary benefit of functions is reusable code. Once a function has been written, it can be used over and over again. This reduces the time spent developing and debugging scripts.
Scripts that use functions naturally have a modular structure and use fewer 'global' variables, therefore they are much easier to understand, debug and maintain.
What do they look like?
All the functions in the library are based on the following template:-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:<Function Name> <Parameter list>
::
:: By: <Author/date/version information>
::
:: Func: <Function description>
::
:: Args: <Argument description>
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
<Body of function>
endlocal&<Set return values>&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
<Function name> | Name of the function, eg GetDate |
<Parameter list> | List of arguments. This list only serves as a reminder of how to call the function (everything after the function name is ignored by the command interpreter) |
<Author/date/version information> | Self explanatory |
<Function description> | Brief explanation of what the function does and which platforms it has been designed for (NT4, W2K or XP) |
<Argument description> | Detailed description of the functions arguments |
<Body of function> | This is where the function performs its main purpose |
<Set return values> | This is where the function 'returns' any local values back to the calling routine |
0 意見 (+add yours?)
張貼留言