CODE: [Copy to clipboard]
@echo off %{BY knoppix7@www.cndos.net}%
::%1 =>INI文件路径
::%2 =>段名 不用加[]
::%3 =>变量名
::%3为空则读出整段内容
::Command =>模式(如 SET/ECHO) {set:设置为变量 echo:显示 },不能为空
::YH =>设置是否使用引号YH="则加引号 YH不存在则不加
::变量延迟必须在父BAT中被打开
if NOT EXIST "%~1" (Echo File Not Found&GOTO :EOF)
if "%~2"=="" GOTO :EOF
for /F "eol=; tokens=1 delims=:" %%i IN ('findstr /I /n /c:"[%~2]" "%~1" ^| Findstr /v ";" ') DO (
SET line=%%i
)
if "%line%"=="" (echo Section Not Found&GOTO :EOF)
FOR /f "eol=; tokens=1* skip=%line% delims=" %%i IN ('type "%~1"') DO (
set "temp_1=%%i"
if "!temp_1:~0,1!"=="[" (GOTO :EOF) ELSE (
IF "%~3"=="" (%command% %YH%%%i%YH%) ELSE (
FOR /F "tokens=1 delims==" %%a IN ("%%i") DO (
if /i "%%a"=="%~3" (%command% %YH%%%i%YH%)
)
)
)
)
set YH=
set line=
set temp_1=
作为子BAT调用的时候请不要再这个BAT里加setlocal ENABLEDELAYEDEXPANSION