Recent Post

QTP - Files Comparison


'************************************************************************
' QTP - Compare Files
'************************************************************************
path="C:"
file1="MyFile1.txt"
file2="MyFile2.txt"
Call CompareFiles(path, file1, file2)

Public Function CompareFiles(path, file1, file2)
Const ForReading = 1, ForWriting = 2, BinaryCompare = 1
Dim fso, MyFile1, MyFile2, comp, ln1, ln2
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile1 = fso.OpenTextFile(path & "\\" & file1, ForReading)
Set MyFile2 = fso.OpenTextFile(path & "\\" & file2, ForReading)
set DiffFile=fso.createtextfile("c:\diif.txt")
i=0
While MyFile1.AtEndOfStream <> True
ln1 = MyFile1.ReadLine
i=i+1
Wend
j=0
While MyFile2.AtEndOfStream <> True
ln2 = MyFile2.ReadLine
j=j+1
Wend
If i<>j Then
     Reporter.ReportEvent 1, "Line Count ", "Line Count is not equal."
 else
 Reporter.ReportEvent 0, "Line Count ", "Line Count is equal."
End If
MyFile1.Close
MyFile2.Close
Set MyFile1 = fso.OpenTextFile(path & "\\" & file1, ForReading)
Set MyFile2 = fso.OpenTextFile(path & "\\" & file2, ForReading)

Do While ((MyFile1.AtEndOfStream <> True) and (MyFile2.AtEndOfStream <> True))
l1=MyFile1.Line
l2=MyFile2.Line
ln1 = MyFile1.ReadLine
ln2 = MyFile2.ReadLine

comp = strcomp( cstr(ln1),cstr( ln2), BinaryCompare)
If (comp <> 0) then
 DiffFile.writeline l1&cstr(ln1)&"    "&cstr(ln2)
End if
Loop

MyFile1.Close
MyFile2.Close
DiffFile.close

End Function

'************************************************************************

0 comments:

Post a Comment

GAReddy @ OneTestingCenter @ All Articles