Something like a function/method in batch files?

Just for completeness, you can also pass parameters to the function:

Function call

call :myDosFunc 100 "string val"

Function body

:myDosFunc
echo. Got Param#1 %~1
echo. Got Param#2 %~2
goto :eof

You could use the call command :

call:myDosFunc

And then define the function this way :

:myDosFunc    - here starts the function
echo.  here the myDosFunc function is executing a group of commands
echo.  it could do a lot of things
goto:eof

Source : Batch Functions


Placing the reusable functions into a separate batch file would certainly work to simulate a function.

The catch is that you have to use the call command in order to ensure that control returns to the caller after the second batch file finishes executing.

call 5lines.bat
echo this will now get called