来一段啰嗦的、效果低的:
内容会添加到段的末尾- @echo off
- SetLocal EnableDelayedExpansion
-
- echo 请稍等...
-
- rem =============== 设置 ===============
- rem 设置文件名
- set "INF_File=INTL.INF"
-
- rem 设置要删除的行
- set "Delete_Line=simsun.ttc,,,65536"
-
- rem 设置哪一段下面要添加内容
- set Section=[SourceDisksFiles]
-
- rem --------- 段下面要添加的内容 ---------
- rem 必须用双引号括起来
- for %%a in (
- "Sun86.IME = 107,,,,,,,0,0"
- "Sun86.mb = 107,,,,,,,0,0"
- "Sun86.chm = 107,,,,,,,0,0"
- ) do set Append_Lines=!Append_Lines! %%a
- rem --------- /段下面要添加的内容 ---------
-
- rem --------- 替换字符串 ---------
- rem 必须用双引号括起来
- for %%a in (
- "E00E0804=E0860804"
- "pintlgnt.ime=sun86.ime"
- ) do set Old-New=!Old-New! %%a
- rem --------- /替换字符串 ---------
-
- rem 删除含有某字符串的行
- set "ContainStr=pintlgnt"
- rem =============== /设置 ===============
-
- type "%INF_File%" | findstr /nivc:"%Delete_Line%" >.findstr
-
- rem 去除 INF_File 文件的“只读”属性
- attrib -r "%INF_File%"
-
- (for /f "tokens=*" %%a in (.findstr) do (
- set var=%%a
- for %%a in (%Old-New%) do set var=!var:%%~a!
- if "!var:%ContainStr%=!" equ "!var!" (
- if defined Monitor_Section_End (
- set var2=!var: =!
- set var2=!var:*:=!
- if "!var2:~0,1!!var2:~-1!"=="[]" (
- for %%a in (%Append_Lines% !Above_Lines! "!var:*:=!") do (
- echo,%%~a
- )
- set Monitor_Section_End=
- set Above_Lines=
- set Append_Finish=#
- ) else if "!var2!"=="" (
- set Above_Lines=!Above_Lines! "!var:*:=!"
- ) else if "!var2:~0,1!"==";" (
- set Above_Lines=!Above_Lines! "!var:*:=!"
- ) else (
- for %%a in (!Above_Lines! "!var:*:=!") do echo,%%~a
- set Above_Lines=
- )
- ) else (
- if "!var:*:=!"=="%Section%" (
- if not defined Append_Finish set Monitor_Section_End=#
- )
- echo,!var:*:=!
- )
- )
- )) >"%INF_File%"
-
- del .findstr
-
- rem 为了防止要添加内容的段为最后一段。
- if defined Monitor_Section_End (
- for %%a in (%Append_Lines% %Above_Lines%) do echo,%%~a
- ) >>"%INF_File%"
复制代码
[ 本帖最后由 tmplinshi 于 2011-1-10 22:29 编辑 ] |