Skip to content

Instantly share code, notes, and snippets.

@kannkyo
Created July 20, 2018 17:46
Show Gist options
  • Save kannkyo/f98b48236c8047b32eff46cb297dadb2 to your computer and use it in GitHub Desktop.
Save kannkyo/f98b48236c8047b32eff46cb297dadb2 to your computer and use it in GitHub Desktop.
Template bat file
@echo off
setlocal enabledelayedexpansion
:main
pushd %~dp0
rem set arguments
set arg1=%1
set arg2=%2
rem check arguments
call :check_arg1 %arg1%
call :check_arg2 %arg2%
rem import ini files
set ini=test.ini test2.ini
for %%i in (%ini%) do call :import_ini %%i
rem body
echo arg1=%arg1%
echo arg2=%arg2%
echo temp=%temp%
echo temp2=%temp2%
popd
exit /b
:check_arg1
if "%1" == "a" (
rem something to do
) else if "%1" == "b" (
rem something to do
) else (
echo ERROR : wrong argument arg1=%arg1%
exit
)
exit /b
:check_arg2
if "%1" == "a" (
rem something to do
) else if "%1" == "b" (
rem something to do
) else (
echo ERROR : wrong argument arg2=%arg2%
exit
)
exit /b
:import_ini
for /f "tokens=1,2* delims==" %%i in (%1) do (
if not %%i == # (
set %%i=%%j
)
)
exit /b
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment