针对一楼的简单样本,老老实实用纯P代码解了。
假设源文件是ANSI/简中编码- @echo off
- cd /d "D:\Program Files (x86)"
- set "newUser=abc" &set "newPw=999"
- setlocal enabledelayedexpansion
- (for /f "delims=" %%s in (src.ini) do if not defined got (
- (echo,%%s)
- if /i "%%s"=="[SERVER_DATA_2]" (set "got=1")
- ) else (
- if !got! equ 1 (set "newV=%newUser%") else (set "newV=%newPw%")
- for /f "tokens=1 delims==" %%1 in ("%%s") do (echo,%%1=!newV!)
- if !got! equ 2 (set "got=") else (set/a got+=1)
- )
- )>new.ini
- :: move /y new.ini src.ini REM 若保留源文件即注释此行
- endlocal &exit/b
复制代码
|