Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Compare Files - Change Output to a file...?

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Compare Files - Change Output to a file...?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Compare Files - Change Output to a file...? - 5/31/2007 8:04:08 PM   
  Spooner

 

Posts: 41
Score: 0
Joined: 4/16/2007
From: Blighty
Status: offline
Hi,

I have the following code that reads two txt files -


Dim objA
Set objA = Wscript.Arguments
if objA.count <> 2 Then
   Wscript.Echo "FileCompare requires location of 1st file and 2nd file arguments with FQDN."
   Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objF1 = objFSO.OpenTextFile(objA(0), 1)
Set objF2 = objFSO.OpenTextFile(objA(1), 1)
Set objL1 = CreateObject("Scripting.Dictionary")
objL1.CompareMode = vbTextCompare
Set objL2 = CreateObject("Scripting.Dictionary")
objL2.CompareMode = vbTextCompare
' Read first file adding unique value to dictionary object.
Do Until objF1.AtEndOfStream
   strV = objF1.ReadLine
   If (objL1.Exists(strV) = False) Then
       objL1.Add strV, True
   End If
Loop
objF1.Close
' Read the second file.
Wscript.Echo "The following values are only in " & objA(1) & "."
Do Until objF2.AtEndOfStream
   strV = objF2.ReadLine
   If (objL1.Exists(strV) = False) And (objL2.Exists(strV) = False) Then
       Wscript.Echo strV
   End If
' Remove duplicates.
   If (objL1.Exists(strV) = True) Then
       objL1.Remove strV
   End If
' Add unique values to 2nd dictionary object.
   If (objL2.Exists(strV) = False) Then
       objL2.Add strV, True
   End If
Loop
objF2.Close
Wscript.Echo "The following values are only in " & objA(0) & "."
arrL1 = objL1.Keys
For Each strV In arrL1
   Wscript.Echo strV
Next


I'd like change the code to be able to check if the contents of the 1st file are in the 2nd file and then write a text file of any that are missing...

Can anyone suggest a method of doing this. At the moment the output is written to the screen and not a file.

Thanks
Spooner
 
 
Post #: 1
 
 RE: Compare Files - Change Output to a file...? - 5/31/2007 8:48:30 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Did you take a look at this post

http://www.visualbasicscript.com/m_43920/mpage_1/key_compare%2cfiles/tm.htm#43920

(in reply to Spooner)
 
 
Post #: 2
 
 RE: Compare Files - Change Output to a file...? - 5/31/2007 8:55:55 PM   
  Spooner

 

Posts: 41
Score: 0
Joined: 4/16/2007
From: Blighty
Status: offline
Thank you very gdewrance - I had'nt seen that despite a search...I'll take a look now.

Spooner

(in reply to gdewrance)
 
 
Post #: 3
 
 RE: Compare Files - Change Output to a file...? - 5/31/2007 11:42:31 PM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Worth looking at also: http://www.microsoft.com/technet/scriptcenter/resources/qanda/may07/hey0524.mspx

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Spooner)
 
 
Post #: 4
 
 RE: Compare Files - Change Output to a file...? - 5/31/2007 11:52:04 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
thats much better. I had that on my computer somewhere but couldn't find it

(in reply to dm_4ever)
 
 
Post #: 5
 
 
 
  

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 >> Compare Files - Change Output to a file...? Page: [1]
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