Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need a function to compare contents of two text files

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need a function to compare contents of two text files
  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 >>
 Need a function to compare contents of two text files - 9/6/2008 2:33:57 PM   
  joshsri

 

Posts: 1
Score: 0
Joined: 9/6/2008
Status: offline
Original message moved by TNO
Reason :
Hi Everyone,
My Greetings.
I have an Issue.I have to COMPARE the contents of two text files.
For your kind reference i have written my piece of code here :
------------------------------------------------------------
Const ForReading = 1, ForWriting = 2
Dim fso, txtFile, txtFile2, strLine1, strLine2, strMatch
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtFile1 = fso.OpenTextFile("C:\CurrentDIR.txt", ForReading)
Set f = fso.OpenTextFile("C:\Files2Download.txt", ForWriting, True)
Do Until txtFile1.AtEndOfStream
strMatch = False
   strLine1 = txtFile1.Readline
Set txtFile2 = fso.OpenTextFile("C:\LOG.txt", ForReading)
       Do Until txtFile2.AtEndOfStream
           strLine2 = txtFile2.Readline
               If Trim(UCase(strLine2)) = Trim(UCase(strLine1)) Then
                   strMatch = True
               Else 
               End If    
       Loop
       txtFile2.Close
               If strMatch <> True then
                   f.writeline strLine1
               End If
Loop
f.Close
Wscript.Echo "Done"
------------------------------------------------------------
This works fine.
But,I have two/three conditions to be met here.
1. I want the textfiles NOT to be hardcoded.
2. I want this to be written as a function.
3. Also, my First file is static ie the first file is the expected result. My Other two files are generated during runtime. ie the 2nd file which would store Actual result and the 3rd file which would be the differences.

Like if my QAManager writes like this , it should work.
Call FnComptext(tf1,tf2).
It should compare and store the diff in another file.
Plz Help.
Thanks a ton,
Josh Q
 
 
Post #: 1
 
 RE: Need a function to compare contents of two text files - 9/7/2008 12:03:33 PM   
  wjcott

 

Posts: 41
Score: 0
Joined: 9/7/2008
Status: offline
quote:

ORIGINAL: joshsri

But,I have two/three conditions to be met here.
1. I want the textfiles NOT to be hardcoded.
2. I want this to be written as a function.
3. Also, my First file is static ie the first file is the expected result. My Other two files are generated during runtime. ie the 2nd file which would store Actual result and the 3rd file which would be the differences.



Within the guidelines you set, and filling in where some holes, such as where the "difference" file should be stored and what it should be named, this is what I came up with:


      

In this example, the "difference" file would be saved in the same directory as the tested file, tf2Path, with a "dif_" preceding the tested file name. Unless you have a need a return value, there are some benefits for using a subroutine or even a subroutine in its own script. As a subroutine within a script, values can still be passed to the calling subroutine using variables passed by reference, with a separate external script useful for functionality that woul be useful in multiple scripts.

Bill

< Message edited by wjcott -- 9/7/2008 12:23:39 PM >

(in reply to joshsri)
 
 
Post #: 2
 
 
 
  

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 >> Need a function to compare contents of two text files 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