找回密码
 加入
搜索
查看: 7106|回复: 10

[AU3基础] [已解决]如何比较下面2个INI文件的不同并将不容内容写到INI文件中?

  [复制链接]
发表于 2010-9-7 15:13:38 | 显示全部楼层 |阅读模式
本帖最后由 newuser 于 2010-9-8 09:26 编辑

请看下面2个INI文件:
FixedList.ini内容:
[已经安装的补丁]
KB2079403=1
KB2115168=1
KB2160329=1
KB2183461=1
KB2229593=1
KB2264107=1
KB2286198=1
KB923561=1
KB924667-v2=1
KB925398_WMP64=1
KB925902-v2=1
KB927891=1
KB929123=1
KB930178=1
KB932168=1
KB932716-v2=1
KB933729=1
KB935839=1
KB935840=1
KB936021=1
KB936357-v2=1
KB936782=1
KB938127=1
KB938464-v2=1
KB941569=1
KB941644=1
KB942288-v4=1
KB943055=1
KB943460=1
KB943485=1
KB944338-v2=1
KB944653=1
KB945553=1
KB946026=1
KB948496=1
KB950224-v3=1
KB950582=1
KB950762=1
KB950974=1
KB951066=1
KB951698=1
KB951748=1
KB952004=1
KB952069=1
KB952954=1
KB953155=1
KB953298=1
KB954155=1
KB954211=1
KB954708=1
KB955069=1
KB955704=1
KB955759=1
KB956391=1
KB956572=1
KB956802=1
KB956803=1
KB956844=1
KB957097=1
KB958469=1
KB958644=1
KB958687=1
KB958690=1
KB958752=1
KB958869=1
KB959426=1
KB960225=1
KB960714=1
KB960715=1
KB960803=1
KB960859=1
KB961371=1
KB961371-v2=1
KB961373=1
KB961501=1
KB963027=1
KB967715=1
KB967723=1
KB968389=1
KB968537=1
KB968816=1
KB969059=1
KB969897=1
KB969898=1
KB969947=1
KB970238=1
KB970483=1
KB971032=1
KB971314=1
KB971468=1
KB971486=1
KB971513=1
KB971557=1
KB971633=1
KB971657=1
KB971737=1
KB971961=1
KB972260=1
KB972270=1
KB973354=1
KB973507=1
KB973525=1
KB973540=1
KB973815=1
KB973869=1
KB973904=1
KB974112=1
KB974318=1
KB974392=1
KB974455=1
KB974571=1
KB975025=1
KB975254=1
KB975467=1
KB975560=1
KB975562=1
KB975713=1
KB976323=1
KB976325=1
KB977165=1
KB977290=1
KB977816=1
KB977914=1
KB978037=1
KB978207=1
KB978251=1
KB978262=1
KB978338=1
KB978542=1
KB978601=1
KB978695=1
KB978706=1
KB979309=1
KB979482=1
KB979559=1
KB979683=1
KB979907=1
KB980182=1
KB980195=1
KB980218=1
KB980232=1
KB980436=1
KB981350=1
KB982214=1
KB982316=1
KB982381=1
KB982666=1
Q147222=1
ServicePackUninstall=1
WebList.ini:
[补丁服务器]
KB983582=1
KB983583=1
KB982214=1
KB2183461=1
KB2115168=1
KB982316=1
KB2079403=1
KB980436=1
KB2160329=1
KB2286198=1
KB2229593=1
KB979907=1
KB982666=1
KB980218=1
KB982381=1
KB980195=1
KB975562=1
KB978695=1
KB979482=1
KB979559=1
KB978542=1
KB978338=1
KB977816=1
KB976323=1
KB981350=1
KB981349=1
KB979683=1
KB980232=1
KB978601=1
KB979309=1
KB980182=1
KB977165=1
KB977290=1
KB977914=1
KB975560=1
KB971468=1
KB978037=1
KB978262=1
KB975713=1
KB978251=1
KB978706=1
KB978207=1
KB972270=1
KB973904=1
KB974318=1
KB974392=1
KB969947=1
KB958869=1
KB975467=1
KB971486=1
KB969059=1
KB974571=1
KB973525=1
KB974455=1
KB975254=1
KB974112=1
KB969878=1
KB967723=1
KB956844=1
KB956744=1
KB958469=1
KB960859=1
KB971657=1
KB969883=1
KB971557=1
KB973540=1
KB973507=1
KB973869=1
KB973815=1
KB972260=1
KB973346=1
KB961371=1
KB971633=1
KB970238=1
KB968537=1
KB961501=1
KB970483=1
KB969897=1
KB970437=1
KB959426=1
KB963027=1
KB960803=1
KB952004=1
KB961373=1
KB923561=1
KB960225=1
KB958690=1
KB958687=1
KB960714=1
KB955069=1
KB957097=1
KB958644=1
KB938464=1
KB950974=1
KB952954=1
KB943485=1
KB941644=1
如何比较他们的不同,并将不同内容写到一个INI文件内,以下是我的代码,但怎么比都是相同的呢?
Dim  $NewPatchsList=@ScriptDir&"\NewList.ini";下面2个文件对比将不同部分写入
$file = FileOpen(@ScriptDir&"\WebList.ini", 0);来自WEB
$file1=FileOpen(@ScriptDir&"\FixedList.ini",0);来自计算机原有
$file1contents=FileRead($file1)
;MsgBox(0,"",$file1contents)
; 检查打开的文件是否可读
If $file = -1 Then
    MsgBox(0, "错误", "不能打开文件.")
    Exit
EndIf

; 每次读取一行文本,直到文件结束.
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    StringInStr($file1contents,$line)
        If @error = 1 Then
                $New=StringSplit($line,"=",1)
                IniWrite($NewPatchsList,"未安装补丁",$New[1],"1")
        ElseIf @error = 0 Then
                        msgbox(64, "提示", " 2个文件相同")
                        Exit
                EndIf
Wend

FileClose($file)
FileClose($file1)

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-9-7 15:47:26 | 显示全部楼层
回复 1# newuser
等待,别沉!
发表于 2010-9-7 20:18:29 | 显示全部楼层
#include <array.au3>
$fixedlist=IniReadSection("fixedlist.ini","已经安装的补丁")
$weblist=IniReadSection("weblist.ini","补丁服务器")
$n=UBound($weblist)
For $i=1 To UBound($fixedlist)-1
        ReDim $weblist[$n+$i][2]
        $weblist[$n+$i-1][0]=$fixedlist[$i][0]
        $weblist[$n+$i-1][1]=$fixedlist[$i][1]
Next



$fin1 = _ArrayUnique2($weblist)
_ArrayDisplay($fin1)
IniWriteSection("config-new1.ini","client",$fin1,1)
ShellExecute("config-new1.ini")

; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayUnique2
; Description ...: 返回二维数组中独特元素,使用时需要Array.au3支持
; Syntax.........: _ArrayUnique($aArray)
; Author ........: 3mile
; ===============================================================================================================================


Func _ArrayUnique2($Iniread)
    Dim $temparray[$Iniread[0][0]]
    For $i = 1 To $Iniread[0][0]
        $temparray[$i - 1] = $Iniread[$i][0] & "|" & $Iniread[$i][1]
    Next
    $temp = _ArrayUnique($temparray)
    Dim $fin[$temp[0] + 1][2]
    For $i = 1 To $temp[0]
        $finarray = StringSplit($temp[$i], "|")
        $fin[$i][0] = $finarray[1]
        $fin[$i][1] = $finarray[2]
    Next
    $fin[0][0]=UBound($fin)
    Return $fin
EndFunc   ;==>_ArrayUnique2 

评分

参与人数 3金钱 +75 收起 理由
水木子 + 30 学习啦!
newuser + 20 老大,有用AU3打补丁的经验吗?我修复完补丁, ...
afan + 25

查看全部评分

 楼主| 发表于 2010-9-8 08:18:38 | 显示全部楼层
回复 3# 3mile

这段能给讲解下吗?
ReDim $weblist[$n+$i][2]


$weblist[$n+$i-1][0]=$fixedlist[$i][0]


$weblist[$n+$i-1][1]=$fixedlist[$i][1]
发表于 2010-9-8 10:00:02 | 显示全部楼层
回复 4# newuser
ReDim $weblist[$n+$i][2];重定义$weblist数组维数,简单点理解为$weblist增容。


$weblist[$n+$i-1][0]=$fixedlist[$i][0];写入到$weblist[n][0]


$weblist[$n+$i-1][1]=$fixedlist[$i][1];写入到$weblist[n][1]

总的意思是将上一个二维数组增加到另一个二维数组中。相当于_ArrayAdd(),只不过这个只针对二维数组。

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-9-8 10:02:46 | 显示全部楼层
刚刚看到这个问题,我想的是用 _ArraySearch 来对比两个数组中的元素,如果有相同的就删除掉,最终得到的就是不同的内容。
 楼主| 发表于 2010-9-9 07:54:49 | 显示全部楼层
回复 6# 水木子
谢谢.
 楼主| 发表于 2010-9-21 11:42:02 | 显示全部楼层
回复 3# 3mile
老大,再比较一下这2个ini,他们的行数不同,感觉有1条不一样,但是用以上代码比较不出来?
[连接列表文件]
WindowsServer2003-KB2121546-x86-CHS.exe=1
WindowsServer2003-KB2259922-x86-CHS.exe=1
WindowsServer2003-KB982802-x86-CHS.exe=1
WindowsServer2003-KB981322-x86-CHS.exe=1
Windows2003SP2WindowsMedia-KB975558-x86-CHS.exe=1
WindowsServer2003-KB2347290-x86-CHS.exe=1
WindowsServer2003-KB982214-x86-CHS.exe=1
WindowsServer2003-KB2183461-x86-CHS.exe=1
WindowsServer2003-KB2115168-x86-CHS.exe=1
WindowsServer2003-KB982316-x86-CHS.exe=1
WindowsServer2003-KB2079403-x86-CHS.exe=1
WindowsServer2003-KB980436-x86-CHS.exe=1
WindowsServer2003-KB2160329-x86-CHS.exe=1
WindowsServer2003-KB2286198-x86-CHS.exe=1
WindowsServer2003-KB2229593-x86-CHS.exe=1
WindowsServer2003-KB979907-x86-CHS.exe=1
WindowsServer2003-KB982666-x86-CHS.exe=1
WindowsServer2003-KB980218-x86-CHS.exe=1
WindowsServer2003-KB982381-x86-CHS.exe=1
WindowsServer2003-KB980195-x86-CHS.exe=1
WindowsServer2003-KB975562-x86-CHS.exe=1
WindowsServer2003-KB978695-x86-CHS.exe=1
WindowsServer2003-KB979482-x86-CHS.exe=1
WindowsServer2003-KB979559-x86-CHS.exe=1
WindowsServer2003-KB978542-x86-CHS-10030.exe=1
WindowsServer2003-KB978338-x86-CHS-10029.exe=1
WindowsServer2003-KB977816-x86-CHS.exe=1
WindowsServer2003-KB976323-x86-CHS-10024.exe=1
WindowsServer2003-KB981350-x86-CHS.exe=1
WindowsServer2003-KB981349-x86-CHS.exe=1
WindowsServer2003-KB979683-x86-CHS-10021.exe=1
WindowsServer2003-KB980232-x86-CHS.exe=1
WindowsServer2003-KB978601-x86-CHS.exe=1
WindowsServer2003-KB979309-x86-CHS.exe=1
WindowsServer2003-KB980182-x86-CHS.exe=1
WindowsServer2003-KB977165-x86-CHS.exe=1
WindowsServer2003-KB977290-x86-CHS.exe=1
WindowsServer2003-KB977914-x86-CHS.exe=1
WindowsServer2003-KB975560-x86-CHS.exe=1
WindowsServer2003-KB971468-x86-CHS.exe=1
WindowsServer2003-KB978037-x86-CHS.exe=1
WindowsServer2003-KB978262-x86-CHS.exe=1
WindowsServer2003-KB975713-x86-CHS.exe=1
WindowsServer2003-KB978251-x86-CHS.exe=1
WindowsServer2003-KB978706-x86-CHS.exe=1
WindowsServer2003-KB978207-x86-CHS.exe=1
WindowsServer2003-KB972270-x86-CHS.exe=1
WindowsServer2003-KB973904-x86-CHS.exe=1
WindowsServer2003-KB974318-x86-CHS.exe=1
WindowsServer2003-KB974392-x86-CHS.exe=1
WindowsServer2003-KB969947-x86-CHS.exe=1
WindowsServer2003-KB958869-x86-CHS.exe=1
WindowsServer2003-KB975467-x86-CHS.exe=1
WindowsServer2003-KB971486-x86-CHS.exe=1
WindowsServer2003-KB969059-x86-CHS.exe=1
WindowsServer2003-KB974571-x86-CHS.exe=1
WindowsServer2003-KB973525-x86-CHS.exe=1
WindowsServer2003-KB974455-x86-CHS.exe=1
WindowsServer2003-KB975254-x86-CHS.exe=1
WindowsServer2003-KB974112-x86-CHS.exe=1
WindowsMedia9-KB969878-x86-CHS.exe=1
WindowsServer2003-KB967723-x86-CHS.exe=1
WindowsServer2003-KB956844-x86-CHS.exe=1
WindowsServer2003-KB956744-x86-CHS.exe=1
WindowsServer2003-KB958469-x86-CHS.exe=1
WindowsServer2003-KB960859-x86-CHS.exe=1
WindowsServer2003-KB971657-x86-CHS.exe=1
WindowsServer2003-KB969883-x86-CHS.exe=1
WindowsServer2003-KB971557-x86-CHS.exe=1
WindowsServer2003-KB973540-x86-CHS.exe=1
WindowsServer2003-KB973507-x86-CHS.exe=1
WindowsServer2003-KB973869-x86-CHS.exe=1
WindowsServer2003-KB973815-x86-CHS.exe=1
WindowsServer2003-KB972260-x86-CHS.exe=1
WindowsServer2003-KB973346-x86-CHS.exe=1
WindowsServer2003-KB961371-x86-CHS.exe=1
WindowsServer2003-KB971633-x86-CHS.exe=1
WindowsServer2003-KB970238-x86-CHS.exe=1
WindowsServer2003-KB968537-x86-CHS.exe=1
WindowsServer2003-KB961501-x86-CHS.exe=1
WindowsServer2003-KB970483-x86-CHS.exe=1
WindowsServer2003-KB969897-x86-CHS.exe=1
WindowsServer2003-KB970437-x86-CHS.exe=1
WindowsServer2003-KB959426-x86-CHS.exe=1
WindowsServer2003-KB963027-x86-CHS.exe=1
WindowsServer2003-KB960803-x86-CHS.exe=1
WindowsServer2003-KB952004-x86-CHS.exe=1
WindowsServer2003-KB961373-x86-CHS.exe=1
WindowsServer2003-KB923561-x86-CHS.exe=1
WindowsServer2003-KB960225-x86-CHS.exe=1
WindowsServer2003-KB958690-x86-CHS.exe=1
WindowsServer2003-KB958687-x86-CHS.exe=1
WindowsServer2003-KB960714-x86-CHS.exe=1
WindowsServer2003-KB955069-x86-CHS.exe=1
WindowsServer2003-KB957097-x86-ENU.exe=1
WindowsServer2003-KB958644-x86-CHS.exe=1
WindowsServer2003-KB938464-v2-x86-CHS.exe=1
WindowsServer2003-KB950974-x86-CHS.exe=1
WindowsServer2003-KB952954-x86-CHS.exe=1
WindowsServer2003-KB943485-x86-CHS.exe=1
WindowsServer2003-KB941644-x86-CHS.exe=1
Old.ini内容如下:
[不同的文件列表]
Windows2003SP2WindowsMedia-KB975558-x86-CHS.exe=1
WindowsMedia9-KB969878-x86-CHS.exe=1
WindowsServer2003-KB2079403-x86-CHS.exe=1
WindowsServer2003-KB2115168-x86-CHS.exe=1
WindowsServer2003-KB2121546-x86-CHS.exe=1
WindowsServer2003-KB2160329-x86-CHS.exe=1
WindowsServer2003-KB2183461-x86-CHS.exe=1
WindowsServer2003-KB2229593-x86-CHS.exe=1
WindowsServer2003-KB2259922-x86-CHS.exe=1
WindowsServer2003-KB2286198-x86-CHS.exe=1
WindowsServer2003-KB2347290-x86-CHS.exe=1
WindowsServer2003-KB923561-x86-CHS.exe=1
WindowsServer2003-KB938464-v2-x86-CHS.exe=1
WindowsServer2003-KB941644-x86-CHS.exe=1
WindowsServer2003-KB943485-x86-CHS.exe=1
WindowsServer2003-KB950974-x86-CHS.exe=1
WindowsServer2003-KB952004-x86-CHS.exe=1
WindowsServer2003-KB952954-x86-CHS.exe=1
WindowsServer2003-KB955069-x86-CHS.exe=1
WindowsServer2003-KB956744-x86-CHS.exe=1
WindowsServer2003-KB956844-x86-CHS.exe=1
WindowsServer2003-KB957097-x86-ENU.exe=1
WindowsServer2003-KB958469-x86-CHS.exe=1
WindowsServer2003-KB958644-x86-CHS.exe=1
WindowsServer2003-KB958687-x86-CHS.exe=1
WindowsServer2003-KB958690-x86-CHS.exe=1
WindowsServer2003-KB958869-x86-CHS.exe=1
WindowsServer2003-KB959426-x86-CHS.exe=1
WindowsServer2003-KB960225-x86-CHS.exe=1
WindowsServer2003-KB960714-x86-CHS.exe=1
WindowsServer2003-KB960803-x86-CHS.exe=1
WindowsServer2003-KB960859-x86-CHS.exe=1
WindowsServer2003-KB961371-x86-CHS.exe=1
WindowsServer2003-KB961373-x86-CHS.exe=1
WindowsServer2003-KB961501-x86-CHS.exe=1
WindowsServer2003-KB963027-x86-CHS.exe=1
WindowsServer2003-KB967723-x86-CHS.exe=1
WindowsServer2003-KB968537-x86-CHS.exe=1
WindowsServer2003-KB969059-x86-CHS.exe=1
WindowsServer2003-KB969883-x86-CHS.exe=1
WindowsServer2003-KB969897-x86-CHS.exe=1
WindowsServer2003-KB969947-x86-CHS.exe=1
WindowsServer2003-KB970238-x86-CHS.exe=1
WindowsServer2003-KB970437-x86-CHS.exe=1
WindowsServer2003-KB970483-x86-CHS.exe=1
WindowsServer2003-KB971468-x86-CHS.exe=1
WindowsServer2003-KB971486-x86-CHS.exe=1
WindowsServer2003-KB971557-x86-CHS.exe=1
WindowsServer2003-KB971633-x86-CHS.exe=1
WindowsServer2003-KB971657-x86-CHS.exe=1
WindowsServer2003-KB972260-x86-CHS.exe=1
WindowsServer2003-KB972270-x86-CHS.exe=1
WindowsServer2003-KB973507-x86-CHS.exe=1
WindowsServer2003-KB973525-x86-CHS.exe=1
WindowsServer2003-KB973540-x86-CHS.exe=1
WindowsServer2003-KB973815-x86-CHS.exe=1
WindowsServer2003-KB973869-x86-CHS.exe=1
WindowsServer2003-KB973904-x86-CHS.exe=1
WindowsServer2003-KB974112-x86-CHS.exe=1
WindowsServer2003-KB974318-x86-CHS.exe=1
WindowsServer2003-KB974392-x86-CHS.exe=1
WindowsServer2003-KB974455-x86-CHS.exe=1
WindowsServer2003-KB974571-x86-CHS.exe=1
WindowsServer2003-KB975254-x86-CHS.exe=1
WindowsServer2003-KB975467-x86-CHS.exe=1
WindowsServer2003-KB975560-x86-CHS.exe=1
WindowsServer2003-KB975562-x86-CHS.exe=1
WindowsServer2003-KB975713-x86-CHS.exe=1
WindowsServer2003-KB976323-x86-CHS-10024.exe=1
WindowsServer2003-KB977165-x86-CHS.exe=1
WindowsServer2003-KB977290-x86-CHS.exe=1
WindowsServer2003-KB977816-x86-CHS.exe=1
WindowsServer2003-KB977914-x86-CHS.exe=1
WindowsServer2003-KB978037-x86-CHS.exe=1
WindowsServer2003-KB978207-x86-CHS.exe=1
WindowsServer2003-KB978251-x86-CHS.exe=1
WindowsServer2003-KB978262-x86-CHS.exe=1
WindowsServer2003-KB978338-x86-CHS-10029.exe=1
WindowsServer2003-KB978542-x86-CHS-10030.exe=1
WindowsServer2003-KB978601-x86-CHS.exe=1
WindowsServer2003-KB978695-x86-CHS.exe=1
WindowsServer2003-KB978706-x86-CHS.exe=1
WindowsServer2003-KB979309-x86-CHS.exe=1
WindowsServer2003-KB979482-x86-CHS.exe=1
WindowsServer2003-KB979559-x86-CHS.exe=1
WindowsServer2003-KB979683-x86-CHS-10021.exe=1
WindowsServer2003-KB979907-x86-CHS.exe=1
WindowsServer2003-KB980182-x86-CHS.exe=1
WindowsServer2003-KB980195-x86-CHS.exe=1
WindowsServer2003-KB980218-x86-CHS.exe=1
WindowsServer2003-KB980232-x86-CHS.exe=1
WindowsServer2003-KB980436-x86-CHS.exe=1
WindowsServer2003-KB981322-x86-CHS.exe=1
WindowsServer2003-KB981349-x86-CHS.exe=1
WindowsServer2003-KB981350-x86-CHS.exe=1
WindowsServer2003-KB982214-x86-CHS.exe=1
WindowsServer2003-KB982316-x86-CHS.exe=1
WindowsServer2003-KB982381-x86-CHS.exe=1
WindowsServer2003-KB982666-x86-CHS.exe=1
WindowsServer2003-KB982802-x86-CHS.exe=1
发表于 2010-9-21 13:25:57 | 显示全部楼层
回复 8# newuser
已经知道等号右边必然为1,“=1”,似乎不用那么麻烦吧。
以下代码未测试。
$array1=stringregexp(fileread("new.ini"),'(.+)=.*',3)
$array2=stringregexp(fileread("old.ini"),'(.+)=.*',3)
for $i=1 to ubound($array2)-1
     _arrayadd($array1,$array2[$i])
next
$new_array=_ArrayUnique($array1)
_arraydisplay($new_array)
 楼主| 发表于 2010-9-21 13:45:08 | 显示全部楼层
回复 9# 3mile
没任何显示!
#include <Array.au3>
$array1=stringregexp(fileread("new.ini"),'(.+)=.*',3)
;检查字符串fileread("new.ini")是否符合给定的表达式(.+)=.*,3表示返回完全匹配的数组
$array2=stringregexp(fileread("old.ini"),'(.+)=.*',3)
for $i=1 to ubound($array2)-1;就是将$array2数组的每一个元素
     _arrayadd($array1,$array2[$i]);将$array2[$i]添加到数组$array1里
next
$new_array=_ArrayUnique($array1);返回数组的唯一元素
_arraydisplay($new_array)
另外,楼上的代码就算大材小用,也应能比出不同部分,可是没比出来啊?他们的行数差一行,我用了最笨的纸质方法对比了还是 没找出来!郁闷!
发表于 2013-7-1 08:26:17 | 显示全部楼层
請問一下 _arraydisplay($XXX) 一顯示出來, 動作就暫停了.
一定要關掉它的視窗才能繼續動作, 有沒有方式可以讓它自行關閉呢? 謝謝~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-17 16:38 , Processed in 0.095052 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表