Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I compare 2 text files?
#1
Solved: 11 Years, 4 Months, 3 Weeks ago

I need to compare and validate 2 reports(text file). The reports need to be called from locations and then compare both of them and the difference needs to be reported as result.

Let me know the possible ways for this. Or what can I do. I have QTP 11 , windows 7, ie 8

Thank you
Avanthika
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Might be helpful to you.
Code:
Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject(“Scripting.FileSystemObject”)

If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)

CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)

CompareFiles = StrComp(Str1, Str2, 0)

If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop

File1.Close()
File2.Close()
End Function


Regards,
Sankalp
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
For this I am getting the syntax error when I try to run this in test. Please help.

Thank you
avanthika
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
Thank you for the script. I am successful in running the script mentioned above. Can I report the difference between the 2 files as Result line by line. Please help.

Thanks
Avanthika
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi,
Code:
Set FS = CreateObject("Scripting.FileSystemObject")
use the above line.u will not get a error

Thanks,
Arul
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to Validate Text filed is blank after clicking on the Text box balak89 3 4,973 09-13-2015, 12:06 AM
Last Post: ADITI1992
  Compare WebTable Elements saraiado 1 2,580 06-11-2015, 06:54 PM
Last Post: venkatesh9032
  How to compare two binary values Naresh 0 2,369 09-09-2014, 05:06 PM
Last Post: Naresh
  Capture Value through Text Checkpoint and compare with datatable value hamzaz 2 4,803 03-06-2014, 12:52 AM
Last Post: mallika.g
  QTP Should open files(say txt files) it can be n number from a folder. Shiv Y 1 2,813 12-18-2013, 01:45 AM
Last Post: mlkrqtp

Forum Jump:


Users browsing this thread: 1 Guest(s)