Windows .bat/.cmd function library in own file?

后端 未结 6 2040
春和景丽
春和景丽 2021-02-05 14:50

there is a nice way to build functions in DOS .bat/.cmd script. To modularize some installation scripts, it would be nice to include a file with a library of functions into an .

6条回答
  •  梦如初夏
    2021-02-05 15:46

    There is an easier way to load the library functions each time the main file is executed. For example:

    @echo off
    rem If current code was restarted, skip library loading part
    if "%_%" == "_" goto restart
    rem Copy current code and include any desired library
    copy /Y %0.bat+lib1.bat+libN.bat %0.full.bat
    rem Set the restart flag
    set _=_
    rem Restart current code
    %0.full %*
    :restart
    rem Delete the restart flag
    set _=
    rem Place here the rest of the batch file
    rem . . . . .
    rem Always end with goto :eof, because the library functions will be loaded
    rem after this code!
    goto :eof
    

提交回复
热议问题