If you use the same subroutine(s) in many batch files, it could be useful to put them all in one file (Library.cmd) then include (call) this library from your batch files. So, you can update your subroutine(s) once in the Library.
a script (caller.cmd) calling the subroutine LENTS in the Library:
Code: Select all
@SETLOCAL ENABLEDELAYEDEXPANSION
Call Library.cmd LENTS "WinRAR\WinRAR.exe" "LEN"
Echo.Chars: [%LEN%]
Pause
Exit
And the Library.cmd:
Code: Select all
@ECHO OFF
IF /i NOT "%~1"=="" (
Call:%~1 "%~2" "%~3" "%~4" "%~5" "%~6" "%~7" "%~8"
) ELSE (ECHO.Missing SubRoutine Name^! Press To End&Pause>Nul&EXIT)
GOTO:END
:LENTS
SET s_=%~1
SET /a %~2=0
:LOOP
SET /a L_+=1
SET s_=%s_:~0,-1%
IF "%s_%"=="" (SET %~2=%L_%&GOTO:EOF) ELSE GOTO:LOOP
GOTO:EOF
:END
Any comment, improvement are welcome.
Thanks and regards.