Automating QTP Test Automation Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map
File Function - CompareThis function compares two text files and reports if they are identical. Download it Here (right-click and then save target as). (NOTE - you can just cut & paste from below, but the formatting will have multiple spaces instead of tabs).
'=========================================================================
Function zFile_Compare(sFile1, sFile2) 'Compares two text files (it assumes they exist) 'Usage: 'iRet = zFile_Compare(sFile1, sFile2) 'Where 'sFile1 is the first file 'sFile2 is the second file 'Returns 'True if they are the same 'False if they are different Dim oFso, oFile1, oFile2, sLine1, sLine2, iResult zFile_Compare = True Set oFso = CreateObject("Scripting.FileSystemObject") Set oFile1 = oFso.GetFile(sFile1) Set oFile2 = oFso.GetFile(sFile2) If oFile1.Size <> oFile2.Size Then 'Files are different sizes - Set flag zFile_Compare = False Else Set oFile1 = oFso.OpenTextFile(sFile1, 1) Set oFile2 = oFso.OpenTextFile(sFile2, 1) Do While ((oFile1.AtEndOfStream <> True) Or (oFile2.AtEndOfStream <> True)) sLine1 = oFile1.ReadLine sLine2 = oFile2.ReadLine iResult = strComp(sLine1,sLine2,0) If (iResult <> 0) Then 'Files are different content - Set flag zFile_Compare = False Exit Do End If Loop oFile1.Close oFile2.Close End If Set oFso = Nothing End Function '========================================================================= |