Please resolve this issue in comparing 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: Please resolve this issue in comparing 2 text files (/Thread-Please-resolve-this-issue-in-comparing-2-text-files) |
Please resolve this issue in comparing 2 text files - kkishore12345 - 01-11-2009 I have written the following function to compare 2 text files. Code: Public Function CompareFiles2 (FilePath1, FilePath2) In the Main action, I have written the following code: Code: FilePath1="C:\Temp\" & DataTable("FileName",dtGlobalSheet) & "_" & DataTable("GLang",dtGlobalSheet) & "_" & "privacy" & "_" & "Actual" & ".txt" Please resolve this issue ASAP. Kishore RE: Please resolve this issue in comparing 2 text files - kkishore12345 - 01-11-2009 I tried with the following function Code: Dim fso, MyFile1, MyFile2, comp, ln1, ln2 In the Main action, I wrote the following code Code: path="C:\Temp\" [quote=kkishore12345] I have written the following function to compare 2 text files. Public Function CompareFiles2 (FilePath1, FilePath2) Dim FS, File1, File2 Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.GetFile(FilePath1).Size <> FSO.GetFile(FilePath2).Size Then CompareFiles2 = True Exit Function End If Set File1 = FSO.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FSO.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles2 = False Do While File1.AtEndOfStream = False Str1 = File1.Read(1000) Str2 = File2.Read(1000) CompareFiles2 = StrComp(Str1, Str2, 0) If CompareFiles2 <> 0 Then CompareFiles2 = True Exit Do End If Loop File1.Close() File2.Close() End Function In the Main action, I have written the following code: FilePath1="C:\Temp\" & DataTable("FileName",dtGlobalSheet) & "_" & DataTable("GLang",dtGlobalSheet) & "_" & "privacy" & "_" & "Actual" & ".txt" FilePath2= "C:\Temp\" & DataTable("FileName",dtGlobalSheet) & "_" & DataTable("GLang",dtGlobalSheet) & "_" & "termsandprivacy" & ".txt" If CompareFiles2(FilePath1,FilePath2) = False Then Reporter.ReportEvent micPass, "Files are same","Passed" Else Reporter.ReportEvent micFail, "Files are different","Fail" End If I am not getting the result, getting error in function. Please resolve this issue ASAP. Kishore |