返回列表 发帖
回复 15# yym黄诗瑶


for /f %%h ... 这种命令会导致 ini 文件里面分号开头的行被忽略
findstr /n "." "1.ini" 的目的是为了在每行开头加上行号和冒号
for /f "tokens=1* delims=:" %%h ... 以冒号作为分隔符,%%h获取到行号(在本例中没有用处),%%i获取到剩余内容(也就是ini文件原始内容)
set "str=%%i" 变量str里面保存的就是ini某一行的内容

"!str:SourcePath=!" 本身是一个字符串替换,意思把变量str里面SourcePath这个字符串替换为空
if "!str:SourcePath=!" neq "%%i" 是为了判断该行内容是否包含字符串 SourcePath

TOP

本帖最后由 老刘1号 于 2017-3-22 19:11 编辑

我还就不用批了
另存为INF
[Version]
Signature="$Chicago$"
[DefaultInstall]
UpdateInis=2333
[2333]
%01%\Test.ini,Path,SourcePath=2333,SourcePath=%10%
%01%\Test.ini,Path,NeedUpdatePath=2333,NeedUpdatePath=%10%COPY

TOP

本帖最后由 老刘1号 于 2017-3-22 23:02 编辑

回复 5# codegay


   很巧,INF也是安装工具
INI文件修改是INF为数不多的实用功能之一

TOP

D:\tmp>perl -lpe "   $_ = $1. '=c:\windows'  if( m/(SourcePath|NeedUpdatePath)/ )   "  test.ini
[Path]
;产品名
Project=I7
;分支号
Branch=R1.2
;产品名+分支号
ProBranch=I7_R1.2
;源文件路径
SourcePath=c:\windows
;需更新文件路径
NeedUpdatePath=c:\windows

TOP

回复 16# ShowCode
set ListenPort=0
set IsSupport=0
goto dealmanager1  
set EableCall=1
set EableOneMoreCall=1
set Eable60P=0
goto dealmanager2
set Conference_Module=Meeting
goto dealmanager3
:dealmanager1
(for /f " delims=:" %%h in ('findstr /n "." "!SourcePath!\Config\CoreDefConfig.ini"') do (
    set "str=%%i"
    if "!str:ListenPort=!" neq "%%i" (
        echo ListenPort=!ListenPort!
    ) else if "!str:IsSupport=!" neq "%%i" (
        echo IsSupport=!IsSupport!
    ) else (
        echo,%%i
    )
))>"!SourcePath!\Config\2.ini"
del "!SourcePath!\Config\CoreDefConfig.ini"
rename "!SourcePath!\Config\2.ini" "CoreDefConfig.ini"
:dealmanager2
(for /f "tokens=1* delims=:" %%h in ('findstr /n "." "!SourcePath!\Config\I7DefConfig.ini"') do (
    set "str=%%i"
    if "!str:EableCall=!" neq "%%i" (
        echo EableCall=!EableCall!
    ) else if "!str:EableOneMoreCall=!" neq "%%i" (
        echo EableOneMoreCall=!EableOneMoreCall!
    )  else if "!str:Eable60P=!" neq "%%i" (
        echo Eable60P=!Eable60P!
    ) else (
        echo,%%i
    )
))>"!SourcePath!\Config\3.ini"
del "!SourcePath!\Config\I7DefConfig.ini"
rename "!SourcePath!\Config\3.ini" "I7DefConfig.ini"
:dealmanager3
(for /f "tokens=1* delims=:" %%h in ('findstr /n "." "!SourcePath!\Module.ini"') do (
    set "str=%%i"
    if "!str:Conference_Module=!" neq "%%i" (
        echo Conference_Module=!Conference_Module!
    ) else (
        echo,%%i
    )
))>"!SourcePath!\4.ini"
del "!SourcePath!\Module.ini"
rename "!SourcePath!\4.ini" "Module.ini"COPY
也是替换文本,只有第一个dealmanager1修改成功,第二个dealmanager2修改失败,等号后面没有值,为空,第三个deal也有问题,很奇怪。

TOP

返回列表