- dim r(1),file(1),read(1)
- set fso=CreateObject("Scripting.FileSystemObject")
- Set RegExp = New RegExp
- file(0)="1.txt"
- file(1)="2.txt"
- n=2
- for i = 0 to 1
- if not fso.fileexists(file(i)) then
- n=n-1
- err_msg="'"&file(i)&"' "
- end if
- next
- if n=0 then
- err_msg="'"&file(0)&"' 和 '"&file(1)&"' "
- end if
- if n<>2 then
- msgbox err_msg&"不存在,请检查vbs代码是否修改正确!",16,"Error":wsh.quit
- end if
- for i = 0 to 1
- if fso.getfile(file(i)).size=0 then
- n=n-1:a=a+1
- err_msg="'"&file(i)&"' "
- end if
- next
- if n=0 then
- err_msg="'"&file(0)&"' 和 '"&file(1)&"' "
- end if
- if a=1 then a=empty
- if n<>2 then
- msgbox err_msg&"文件内容为空,请检查这"&a&"个"&fso.getextensionname(file(0))&"是否是需要修改的文件!",16,"Error":wsh.quit
- end if
- n=2
- for i = 0 to 1
- read(i)=fso.opentextfile(file(i)).readall
- next
- With RegExp
- .Global = -1
- .multiline=-1
- .pattern="^(.*)=(.*$)"
- if .test(read(0)) then
- for each match in .execute(read(0))
- r(0)=match.submatches(0)
- r(1)=match.submatches(1)
- .pattern="(^"&r(0)&"=)(.*)$"
- read(1)=.Replace(read(1),"$1"&r(1))
- next
- fso.createtextfile(file(1)).write read(1)
- else
- n=n-1
- err_msg="'"&file(0)&"' "
- end if
- if not .test(read(1)) then
- n=n-1
- err_msg="'"&file(1)&"' "
- end if
- if n=0 then
- err_msg="'"&file(0)&"' 和 '"&file(1)&"' "
- end if
- if n<>2 then
- msgbox "没有在 '"&err_msg&"' 中找到相应匹配!",16,"Error":wsh.quit
- end if
- End With
复制代码 声明:
本程序是将样本中每一行对应的数据中末尾=号后面的数据进行更替.
如果你对此代码表示不满意还可以进行修整,添加你需要的代码或者批量修改都行!使用范围不仅限INI文件.
如果你感到日常频繁使用软件或者游戏等,需要大量查找/修改感到烦恼时可以考虑用来一键替换. |