Micro Focus QTP (UFT) Forums
How do I compare 2 text files? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How do I compare 2 text files? (/Thread-How-do-I-compare-2-text-files)



How do I compare 2 text files? - avanthika - 12-09-2011


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


RE: How do I compare 2 text files? - sshukla12 - 12-09-2011

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


RE: How do I compare 2 text files? - avanthika - 12-09-2011

For this I am getting the syntax error when I try to run this in test. Please help.

Thank you
avanthika


RE: How do I compare 2 text files? - avanthika - 12-10-2011

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


RE: How do I compare 2 text files? - Arul - 12-10-2011

Hi,
Code:
Set FS = CreateObject("Scripting.FileSystemObject")
use the above line.u will not get a error

Thanks,
Arul