View Single Post
  #1 (permalink)  
Old December 20th, 2004, 12:24 PM
mollem mollem is offline
Registered User
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare 2 Text Files

What I would like to do is compare two text files and output differences to a third text file. If the entry from the txtFile1.txt is not in txtFile2.txt write line to txtFile3.txt. txtFile1.txt will have about 1800 lines and txtFile2.txt will have about 400-900 lines.
Code:
Const ForReading = 1, ForWriting = 2
Dim fso, txtFile, txtFile2, strLine1, strLine2, strMatch
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtFile1 = fso.OpenTextFile("c:\txtFile1.txt", ForReading)
Set txtFile2 = fso.OpenTextFile("c:\txtFile2.txt", ForReading)
Set f = fso.OpenTextFile("c:\results.txt", ForWriting, True)

Do Until txtFile1.AtEndOfStream
    strLine1 = txtFile1.Readline
        Do Until txtFile2.AtEndOfStream
            strLine2 = txtFile2.Readline
                If Trim(UCase(strLine2)) = Trim(UCase(strLine1)) Then
                    strMatch = True
                Else  Removed
                    f.WriteLine strLine1 & "    " & strLine2   Removed
                End If
        Loop
                If strMatch <> True then
                    f.writeline strLine1
                End If
Loop
f.Close
Wscript.Echo "Done"
The output from this is the first line from txtFile1.txt and every line from txtFile2.txt.

Any help would be greatly appreciated.

Thanks in advance,
Mike

**EDIT**
I think that I may have fixed one of the errors in my logic.(changes in bold) However, I am still having problems.
Reply With Quote