a function is a set of statements organized together to perform a specific task. in batch scripts, a similar approach is adopted to group logical statements together to form a function.
as like any other languages, functions in batch script follows the same procedure −
- function declaration − it tells the compiler about a function's name, return type, and parameters. 
- function definition − it provides the actual body of the function. 
function definition
in batch script, a function is defined by using the label statement. when a function is newly defined, it may take one or several values as input 'parameters' to the function, process the functions in the main body, and pass back the values to the functions as output 'return types'.
every function has a function name, which describes the task that the function performs. to use a function, you "call" that function with its name and pass its input values (known as arguments) that matches the types of the function's parameters.
following is the syntax of a simple function.
:function_name do_something exit /b 0
- the function_name is the name given to the function which should have some meaning to match what the function actually does. 
- the exit statement is used to ensure that the function exits properly. 
following is an example of a simple function.
example
:display set /a index=2 echo the value of index is %index% exit /b 0
| s.no | functions & description | 
|---|---|
| 1 | calling a function a function is called in batch script by using the call command. | 
| 2 | functions with parameters functions can work with parameters by simply passing them when a call is made to the function. | 
| 3 | functions with return values functions can work with return values by simply passing variables names | 
| 4 | local variables in functions local variables in functions can be used to avoid name conflicts and keep variable changes local to the function. | 
| 5 | recursive functions the ability to completely encapsulate the body of a function by keeping variable changes local to the function and invisible to the caller. | 
| 6 | file i/o in batch script, it is possible to perform the normal file i/o operations that would be expected in any programming language. | 
| 7 | creating files the creation of a new file is done with the help of the redirection filter >. this filter can be used to redirect any output to a file. | 
| 8 | writing to files content writing to files is also done with the help of the redirection filter >. this filter can be used to redirect any output to a file. | 
| 9 | appending to files content writing to files is also done with the help of the double redirection filter >>. this filter can be used to append any output to a file. | 
| 10 | reading from files reading of files in a batch script is done via using the for loop command to go through each line which is defined in the file that needs to be read. | 
| 11 | deleting files for deleting files, batch script provides the del command. | 
| 12 | renaming files for renaming files, batch script provides the ren or rename command. | 
| 13 | moving files for moving files, batch script provides the move command. | 
| 14 | batch files – pipes the pipe operator (|) takes the output (by default, stdout) of one command and directs it into the input (by default, stdin) of another command. | 
| 15 | batch files – inputs when a batch file is run, it gives you the option to pass in command line parameters which can then be read within the program for further processing. | 
| 16 | using the shift operator one of the limitations of command line arguments is that it can accept only arguments till %9. let’s take an example of this limitation. | 
| 17 | folders in batch script, it is possible to perform the normal folder based operations that would be expected in any programming language. | 
| 18 | creating folders the creation of a folder is done with the assistance of the md (make directory) command. | 
| 19 | listing folder contents the listing of folder contents can be done with the dir command. this command allows you to see the available files and directories in the current directory. | 
| 20 | deleting folders for deleting folders, batch scripting provides the del command. | 
| 21 | renaming folders for renaming folders, batch script provides the ren or rename command. | 
| 22 | moving folders for moving folders, batch script provides the move command. | 
