Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File compare

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,31644
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File compare
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 File compare - 2/28/2006 10:28:20 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
I need to compare two ini files and updating one based on the comparison. One file resides in the webserver, which would be compare with the ini file in the client. My current idea is to create a batch file with the server-ini-file and a vbscipt which would compare the two files at the client site and update the client ini file. Is this possible, since I am new to vbscript, I am not sure of the things I can do with it. Also if someone has a better idea of implementing the comparison I would welcome the idea and appreciate the help.

Thanks

PS: I would be indebted to the replier for life if I can get an answer asap. :p

 
 
Post #: 1
 
 RE: File compare - 2/28/2006 11:50:35 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
To what extent do you need to compare? If different then ... or do you need to know what is different?


Cybex

_____________________________

Common sense is not so common.

(in reply to ylnwwd)
 
 
Post #: 2
 
 RE: File compare - 2/28/2006 1:14:28 PM  1 votes
  binHEX


Posts: 9
Score: 1
Joined: 9/2/2005
Status: offline
quote:

ORIGINAL: ylnwwd

I need to compare two ini files and updating one based on the comparison. One file resides in the webserver, which would be compare with the ini file in the client. My current idea is to create a batch file with the server-ini-file and a vbscipt which would compare the two files at the client site and update the client ini file. Is this possible, since I am new to vbscript, I am not sure of the things I can do with it. Also if someone has a better idea of implementing the comparison I would welcome the idea and appreciate the help.

Thanks

PS: I would be indebted to the replier for life if I can get an answer asap. :p




If both files are intended to be identical, and you know that the server-side file is ok, then I would suggest reading each ini file into a text variable, and then compare the two variables.  If they are different, then copy the server-side file to the client.
Here's a simple scrap of script to get you started:

      

(in reply to ylnwwd)
 
 
Post #: 3
 
 RE: File compare - 3/1/2006 12:24:28 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
Thank you binHEX, I would try out this code.

The server side ini file would be the most updated. The client side has to be updated based on the server side ini file. But the current entries in the client ini file  should not be over written (just needs to have a couple of new entries from the server).

Since ini files have sections, this ini file also has corelated sections.....if there is a new entry in one sections eg: item 10...the corresponding item 10 in other sections need to be updated.

I hope I am not asking for too much information which is probably trivial.

Thanks a lot in advance for all the help

(in reply to binHEX)
 
 
Post #: 4
 
 RE: File compare - 3/1/2006 2:23:38 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
why not just go by the modified date? it doesnt matter what the modification is at that point, it would replace the older version.

quick and easy

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ylnwwd)
 
 
Post #: 5
 
 RE: File compare - 3/1/2006 2:28:56 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Let me see if I can clarify the problem and hopefully make sure that I understand it completely. There is an INI file on the server and one on the client. There are some options that you would like updated on the client if they are different from the server but not all options. You don't want the client INI to update the server INI ever. Is this a correct summation?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 6
 
 RE: File compare - 3/1/2006 2:33:03 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
kirrilian,

Thanks for your reply. The ini file in the client side has data inputs provided by the particular client. I should not delete these entries, instead just add some entries depending on the serverside ini, and also not copy duplicate entries....

so i guess what i would need is a line by line check to verify the data.....this is ok probably to check just a normal text file...but since the ini has sections and i need to update these sections based on entries in one section. Is this possible using vbscript....

(in reply to kirrilian)
 
 
Post #: 7
 
 RE: File compare - 3/1/2006 2:36:45 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
It is possible. Is the smmation that I posted correct? If it is then I would recommend using a dictionary to hold each INI file. There may even be some INI file code out on the web have you checked?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 8
 
 RE: File compare - 3/1/2006 2:41:05 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
ebgreen

Yes that is correct.

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: File compare - 3/1/2006 2:45:08 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Any chance you could post a sample of the ini file and let us know which items on the server should override the client and which items should never be changed on the client? YOu can of course obfuscate any security sensitive info.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 10
 
 RE: File compare - 3/1/2006 2:51:44 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
ebgreen...

this is a sample of my ini file...

[Section1]
Item1=xyz
Item2=abc
...
...
Item25=ggg
[Section2]
Item1=1
Item2=2
...
...
Item25=25
[Section3]
Item1=
Item2=
...
...
Item25=

The client and the server has the same sections

I would need to check one of these sections (eg section 2) ...check if the entries in the client match the entries in the server....if they do leave the item entry alone...if they dont ...change the item (eg item 2) in all sections which compares to the server ini....

If item 2 = 2 in client and Item2 = 10 in server...I would have to change the data of Item2 in client in all the sections....

Another problem which I just thought of is that.... the main section (by which the comparison occurs) is sorted alphabetically and similarly the corresponding sections...so if I add an entry in the main sections....the remaining entries of all sections need to be sorted accordingly...

I hope I was clear...and not confusing you.

Thanks

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: File compare - 3/1/2006 3:00:03 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I'm sorry I have a really bad headache and am having a problem concentrating today. ;)

So if this were the server INI:
[Section1]
Item1=foo
Item2=abc

[Section2]
Item1=1
Item2=2

[Section3]
Item1=
Item2=


And this were the client:
[Section1]
Item1=xyz
Item2=abc


[Section2]
Item1=1
Item2=2

[Section3]
Item1=
Item2=

Then Item1 would be changed in every section of the client INI because the Server value is different. Or would it only be changed in sections where the client had some value already?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 12
 
 RE: File compare - 3/1/2006 3:08:45 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
ebgreen,

thank you so much for helping me...I hope its not me giving you the headache!! :p

in the ini example...the server has an entry foo which the client does not.....So my program has to add this value as a new entry to the client ini (including the corresponding entries in the other sections)

Also it has to be sorted...so the resulting ini should be something like this..

So if this were the server INI:
[Section1]
Item1=abc
Item2=foo

[Section2]
Item1=1
Item2=2

[Section3]
Item1= xxx
Item2= yyy


And this were the client:
[Section1]
Item1=abc
Item2=xyz

[Section2]
Item1=1
Item2=3

[Section3]
Item1= xxx
Item2= zzz

The resultant ini should be

[Section1]
Item1=abc
Item2=foo
Item3=xyz

[Section2]
Item1=1
Item2=2
Item3=3

[Section3]
Item1= xxx
Item2=yyy
Item2= zzz


(in reply to ebgreen)
 
 
Post #: 13
 
 RE: File compare - 3/1/2006 3:29:02 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
So each section is just a sorted list of the values in that section?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 14
 
 RE: File compare - 3/1/2006 3:41:24 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
not all sections need to be sorted, just one primary id section which would be sorted...the remaining sections are arranged in accordance to this primary id section.

thanks

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: File compare - 3/1/2006 3:45:15 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Ok, I'm back to being confused.  There is a primary ID section? Which section is that? Does it have an entry for every datum that is in all the other sections?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 16
 
 RE: File compare - 3/1/2006 3:59:42 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
Im sorry for confusing you...

In my ini the primary section is the one which I choose to compare by...right now I am choosing to compare the files based on an id section. Not all sections have the same number of items. I have around 10 sections of which 7 have corresponding data the remaining 3 are different (they would be client specific, so I dont need to change them).

Also, the id section is sorted alphabetically....and correspondingly the other 7 sections are sorted to match the id sections (these sections are not sorted alphabetically rather sorted as compared to the id section)

I hope I am not aggravating your headache  :p

(in reply to ebgreen)
 
 
Post #: 17
 
 RE: File compare - 3/1/2006 4:05:37 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I don't think anything could make it worse. Since I am having comprehension issues, I think the best solution would be for me to give you general solutions then help you with specific issues that you have with your code. I think the first step will be for you to get/create code that will store the contents of an INI file in a data structure in memory. Let me know when you have that or if you have problems with that then we can move forward.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 18
 
 RE: File compare - 3/1/2006 4:46:05 AM   
  ylnwwd

 

Posts: 15
Score: 0
Joined: 2/28/2006
Status: offline
What type of data structure are you suggesting?  I am thinking, since I do not need to store the entire file, rather just sections, and maybe relate them somehow.

(in reply to ebgreen)
 
 
Post #: 19
 
 RE: File compare - 3/1/2006 5:00:50 AM  1 votes
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I would use a dictionary of dictionaries myself.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ylnwwd)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File compare Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts