Page 1 of 1 1
Topic Options
#33223 - 2002-11-22 04:25 PM Compare INI Files
Austin Offline
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
#33224 - 2002-11-22 04:31 PM Re: Compare INI Files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
as starting pointing...
get familiar with the readprofilestring.
with one liner you can check if the ini-files have same amount of data.
once loaded into variable, you can with simple for each loop check the correctness.
_________________________
!

download KiXnet

Top
#33225 - 2002-11-22 04:32 PM Re: Compare INI Files
Richard H. Administrator Offline
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
#33226 - 2002-11-22 04:40 PM Re: Compare INI Files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I started a reply to this and budda bing, budda bing, Jooel and Richard already posted. Darned this bbchecker... you gotta be quick... forget what I was going to say.

Like Jooel said, get familiar with ReadProfileString(). it can not only pull individual section and key names but also enumerate all sections and/or keys just by passing empty parms.

Richard shows just how simple it is.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33227 - 2002-11-22 04:44 PM Re: Compare INI Files
Austin Offline
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
#33228 - 2002-11-22 04:50 PM Re: Compare INI Files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you enumerate all the sections and put them in an array, you can then use the IsInArray() UDF to compare arrays. Ditto for keys. Comparing key values though do get a bit more involved.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33229 - 2002-11-22 04:56 PM Re: Compare INI Files
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Just one word of warning though...

Blank sections (and entries with no value) appear exactly the same as missing sections and entries.

This may or may not be a concern in your case.

Top
#33230 - 2002-11-22 04:56 PM Re: Compare INI Files
Austin Offline
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 Offline
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 Offline
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 Offline
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 Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 1300 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.05 seconds in which 0.017 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org