部分批處理備忘

@echo off
::-------------------------------------------------------
set nodeIp=
set startPort=
set zoneId=
set runDir=
set dbIp=
set dbPort=3306
set dbUser=root
set dbPasswd=test
set dbName=
set memCacheIp=
set memCachePort=11211
set clientIp=
set outerIp=
set emailAddr=""
::-------------------------------------------------------
set lastkey=
set needExit=0
::-------------------------------------------------------
:loop
if "%1" == "" ( goto :begin ) else (
	if "%lastkey%" == "" (
		set lastkey=%1
	) else (
		set %lastkey%=%1
		set lastkey=
	)
)
shift
goto :loop

:checkKeyNull
if %needExit% equ 1 goto :eof
if "%2" == "" (
	echo "%1 should not be null"
	set needExit=1
)
goto :eof

:setNullKeyVal
if %needExit% equ 1 goto :eof
if "%3" == "" (
	set tmp=%1
	set %tmp%=%2
)
goto :eof

:begin
call :checkKeyNull nodeIp %nodeIp% 
call :checkKeyNull startPort %startPort%
call :checkKeyNull zoneId %zoneId%
call :checkKeyNull runDir %runDir%
call :checkKeyNull dbName %dbName%
call :setNullKeyVal dbIp %nodeIp% %dbIp% 
call :setNullKeyVal memCacheIp %nodeIp% %memCacheIp% 
call :setNullKeyVal clientIp %nodeIp% %clientIp% 
call :setNullKeyVal outerIp %nodeIp% %outerIp% 
if %needExit% equ 1 goto :end

for /f "tokens=*" %%a in ('dir /b win\*.cfg') do (
	call :producefile %%~na
)
goto :eof

:producefile
set filename=%1
set filetype=%filename:~0,-4%
set filedir=%runDir%\%filetype%
md %filedir%
copy /Y win\%filename% %filedir%\%filename%\
goto :eof


:end
exit /b 0
相關文章
相關標籤/搜索