Micro Focus QTP (UFT) Forums

Full Version: How do I compare 2 text files?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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
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
For this I am getting the syntax error when I try to run this in test. Please help.

Thank you
avanthika
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
Hi,
Code:
Set FS = CreateObject("Scripting.FileSystemObject")
use the above line.u will not get a error

Thanks,
Arul