|
-
Sep 20th, 2005, 10:53 AM
#1
Thread Starter
Addicted Member
Compare Text Files
I'm trying to compare two text files and have the difference displayed.
The code below displays both text files, just haven't figured out how to get what's not in either file.
FileOpen(1, File1.Value, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
FileOpen(2, File2.Value, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(1)
Dim TextLine As String = LineInput(1)
Response.Write(TextLine)
Response.Write("<br>")
Loop
FileClose(1)
Do While Not EOF(2)
Dim TextLine2 As String = LineInput(2)
Response.Write(Textline2)
Response.Write("<br>")
Loop
FileClose(2)
Or if you have a better way of comparing two text files I'm open. I'm using vb.net and running a web form.
Thanks
Last edited by Hutty; Sep 20th, 2005 at 11:02 AM.
-
Sep 20th, 2005, 06:32 PM
#2
Re: Compare Text Files
Read each file, line by line and store it in an array. Then loop through the arrays and simply check whether each element of the array (by ordinal) matches the other one. If they match, do nothing, if they don't match, mark them.
Finally, when displaying the two test files, make sure you 'highlight' the differing lines in your display.
-
Sep 21st, 2005, 09:50 AM
#3
Re: Compare Text Files
For a straight compare the easiest way would be to hash the files and then compare the hashes.
TPM
Add yourself to the VBForums Frappr Map!!
-
Sep 21st, 2005, 02:30 PM
#4
Thread Starter
Addicted Member
Re: Compare Text Files
Thanks for responding. I've managed to get the code where it's reading and writing data to the console. Would ultimately want it in a listbox or datagrid though. But anyway, when the lines are displayed it's multiple lines on one line.
I'm getting below on one line. A separate line should begin with CO574.
CO574.GL,11100,21 CO574.GL,12110.01,3970 CO574.GL,12110.02,1104 CO574.GL,12110.02,4
Here's the code that produce the results above.
For Each strFile1Line As String In strFile1Lines
Dim bLineInFile2 As Boolean = False
' Compare the current line in File1 against all lines in File2
For Each strFile2Line As String In strFile2Lines
If strFile1Line = strFile2Line Then bLineInFile2 = True
Next
' If the line is in not in File2 add it to the variable strFile1NotFile2
If Not bLineInFile2 Then strFile1NotFile2 = strFile1NotFile2 & vbCrLf & strFile1Line & vbCrLf
Next
Response.Write(strFile1NotFile2 & vbCrLf)
Response.Write("<br>")
-
Sep 22nd, 2005, 10:02 PM
#5
Thread Starter
Addicted Member
Re: Compare Text Files
I figured it out and it's working the way I want it to on small files. When I try to read a large files it returns "page not found". These files are about 5k, but my ultimate goal is to read files much larger, maybe 30-50mb. Any ideas how to get around current problem?
-
Sep 27th, 2005, 01:28 PM
#6
Thread Starter
Addicted Member
Re: Compare Text Files
Just a followup to see if there are any ideas. Thanks.
-
Jan 29th, 2008, 01:17 AM
#7
New Member
-
Jan 29th, 2008, 11:45 AM
#8
-
Jan 29th, 2008, 12:33 PM
#9
Re: Compare Text Files
BeyondCompare 2. Wonderful software. Even connects over networks and FTP.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|