当遇到空行时,line
变量将被设置为空白,从而删除该变量。您已经检查了它的定义时间。 只需在未定义时添加检查。
for /f "tokens=1,* delims=]" %%A in ('"type Setup.ini|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:PRINTER_JAM_SENSOR_PRESENT: TRUE=PRINTER_JAM_SENSOR_PRESENT: FALSE%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X >>Setup.ini.replaced%~x1
)
if not defined line echo.>>Setup.ini.replaced%~x1
)
额外:这里又是代码,但我建议使用setlocal EnableDelayedExpansion
.
for /F "tokens=1,* delims=]" %%A in ('type Setup.ini ^| find /n /v ""') do (
set "line=%%B"
if defined line (
set "line=!line:PRINTER_JAM_SENSOR_PRESENT: TRUE=PRINTER_JAM_SENSOR_PRESENT: FALSE!"
echo(!line!>>Setup.ini.replaced%~x1
)
if not defined line echo.>>Setup.ini.replaced%~x1
)