#33223 - 2002-11-22 04:25 PM
Compare INI Files
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
I am wanting to develop an ini file compare utility. I was working toward comparing line by line but that is not a good idea because the line may not be in the same place but it may still be present... make sense? So I need to compare section by section but I really do not know how to work toward this.. any direction is appreciated.
Thanks
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#33225 - 2002-11-22 04:32 PM
Re: Compare INI Files
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This is actually very easy. Pseudo-code:
code:
For each section in INI1 Read Section From INI2 THEN For Each Entry in Section in INI1 Read Entry in INI2 THEN If entries do not match print "Dont match" ELSE Print "Entry missing in INI2" ELSE Print "Section missing in INI2"
Now repeat, swapping the ini files around, and don't bother to print the mismatched lines again as they will just be repeats from the first pass.
|
|
Top
|
|
|
|
#33227 - 2002-11-22 04:44 PM
Re: Compare INI Files
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Right I understand the readprofilestring.. but my problem is that there may be entries in an ini that are not in the other.. and I dont necessarily know the sections. I will paly with it.
Thanks
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#33230 - 2002-11-22 04:56 PM
Re: Compare INI Files
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Ok got it.. thanks for the help I will work that direction
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#33231 - 2002-11-22 05:07 PM
Re: Compare INI Files
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Not fully tested, but this should get you started...
code:
Break ON
Function fnCompareIni($sIni1,$sIni2) Dim $iPhase Dim $sFile1,$sFile2 Dim $sSection,$sEntry Dim $sValue1,$sValue2
For $iPhase=0 To 1 If $iPhase $sFile1=$sIni1 $sFile2=$sIni2 Else $sFile1=$sIni2 $sFile2=$sIni1 EndIf For Each $sSection In Split(ReadProfileString($sFile1,"",""),Chr(10)) If $sSection <> "" If ReadProfileString($sFile2,$sSection,"")="" "$sFile2 Section " $sSection " blank or missing" ? Else For Each $sEntry In Split(ReadProfileString($sFile1,$sSection,""),Chr(10)) If $sEntry <> "" $sValue1=ReadProfileString($sFile1,$sSection,$sEntry) $sValue2=ReadProfileString($sFile2,$sSection,$sEntry) If $sValue1<>$sValue2 If $sValue2="" "$sFile2, Section $sSection, Entry $sEntry is blank or missing" ? Else If $iPhase "Section $sSection, Entry $sEntry mismatch" ? EndIf EndIf EndIf EndIf Next EndIf EndIf Next Next EndFunction
|
|
Top
|
|
|
|
#33232 - 2002-11-22 05:14 PM
Re: Compare INI Files
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
WOW.. this is great thanks so much.. with a little tweaking it will be just what I need.. thank you very much.
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#33233 - 2002-11-22 06:59 PM
Re: Compare INI Files
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Ok.. well I cleaned up what was posted earlier and think that this works great for my needs.. just thought I would post finished code out.
code:
Break ON color w+/n cls ?"Enter patch to first ini file: " gets $Ini1 "Enter patch to second ini file: " gets $Ini2
cls "Evalutating Files..."
fnCompareIni($Ini1,$Ini2)
Function fnCompareIni($sIni1,$sIni2) Dim $iPhase Dim $sFile1,$sFile2 Dim $sSection,$sEntry Dim $sValue1,$sValue2
For $iPhase=0 To 1 If $iPhase $sFile1=$sIni1 $sFile2=$sIni2 Else $sFile1=$sIni2 $sFile2=$sIni1 EndIf For Each $sSection In Split(ReadProfileString($sFile1,"",""),Chr(10)) If $sSection <> "" If ReadProfileString($sFile2,$sSection,"")="" ?color y+/n "File: " color w+/n "$sFile2" ?color y+/n "Section: " color w+/n "$sSection" ?color y+/n "Complaint: " color w+/n "Blank or Missing" ?color w+/n Else For Each $sEntry In Split(ReadProfileString($sFile1,$sSection,""),Chr(10)) If $sEntry <> "" $sValue1=ReadProfileString($sFile1,$sSection,$sEntry) $sValue2=ReadProfileString($sFile2,$sSection,$sEntry) If $sValue1<>$sValue2 If $sValue2="" ?color y+/n "File: " color w+/n "$sFile2" ?color y+/n "Section: " color w+/n "$sSection" ?color y+/n "Entry: " color w+/n "$sEntry" ?color y+/n "Complaint: " color w+/n "Blank or Missing" ?color w+/n Else If $iPhase ?color y+/n "Section: " color w+/n "$sSection" ?color y+/n "Entry: " color w+/n "$sEntry" ?color y+/n "Complaint: " color w+/n "Mismatch" ?color w+/n EndIf EndIf EndIf EndIf Next EndIf EndIf Next Next EndFunction
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#33234 - 2002-11-29 11:51 AM
Re: Compare INI Files
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Example Script with syntax highlighting.
Break ON
Function fnCompareIni($sIni1,$sIni2) Dim $iPhase Dim $sFile1,$sFile2 Dim $sSection,$sEntry Dim $sValue1,$sValue2
For $iPhase=0 To 1 If $iPhase $sFile1=$sIni1 $sFile2=$sIni2 Else $sFile1=$sIni2 $sFile2=$sIni1 EndIf For Each $sSection In Split(ReadProfileString($sFile1,"",""),Chr(10)) If $sSection <> "" If ReadProfileString($sFile2,$sSection,"")="" "$sFile2 Section " $sSection " blank or missing" ? Else For Each $sEntry In Split(ReadProfileString($sFile1,$sSection,""),Chr(10)) If $sEntry <> "" $sValue1=ReadProfileString($sFile1,$sSection,$sEntry) $sValue2=ReadProfileString($sFile2,$sSection,$sEntry) If $sValue1<>$sValue2 If $sValue2="" "$sFile2, Section $sSection, Entry $sEntry is blank or missing" ? Else If $iPhase "Section $sSection, Entry $sEntry mismatch" ? EndIf EndIf EndIf EndIf Next EndIf EndIf Next Next EndFunction
fnCompareIni(".\ini1.ini",".\ini2.ini")
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(mole)
and 1300 anonymous users online.
|
|
|