Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please resolve this issue in comparing 2 text files
#1
Not Solved
I have written the following function to compare 2 text files.

Code:
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:

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
Reply
#2
Not Solved
I tried with the following function

Code:
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)
Do While ((MyFile1.AtEndOfStream <> True) OR (MyFile2.AtEndOfStream <> True))
ln1 = MyFile1.ReadLine
If ln1 <> "" Then
reporter.ReportEvent micPass,"File1 reading is successful",ln1
else
reporter.ReportEvent micFail,"File1 reading is NOT successful","fail"
End If
ln2 = MyFile2.ReadLine
If ln2 <> "" Then
reporter.ReportEvent micPass,"File2 reading is successful",ln2
else
reporter.ReportEvent micFail,"File2 reading is NOT successful","fail"
End If
comp = strcomp( ln1, ln2, BinaryCompare)
if (comp <> 0) then
MyFile1.Close
MyFile2.Close
CompareFile = 1
Exit Function
end if
Loop

MyFile1.Close
MyFile2.Close

CompareFile = 0
End Function

In the Main action, I wrote the following code
Code:
path="C:\Temp\"
file1=DataTable("FileName",dtGlobalSheet) & "_" & DataTable("GLang",dtGlobalSheet) & "_" & "privacy" & "_" & "Actual" & ".txt"
file2=DataTable("FileName",dtGlobalSheet) & "_" & DataTable("GLang",dtGlobalSheet) & "_" & "termsandprivacy" & ".txt"


If CompareFile(path,file1,file2)=1 Then
Reporter.ReportEvent micPass, "Files are same","Passed"
Else
Reporter.ReportEvent micFail, "Files are different","Fail"
End If
When I run this test, the test is getting passed. However, as I written the code to print the ln1 and ln2 which means readline from file1 and file2, in the results window, the information present in the attached gif file is displayed.

[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


Attached Files Image(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to Validate Text filed is blank after clicking on the Text box balak89 3 4,893 09-13-2015, 12:06 AM
Last Post: ADITI1992
  UFT taking different script execution timings while comparing 2 excel files. sudheer 0 2,351 06-26-2015, 03:28 PM
Last Post: sudheer
  how resolve "webedit" cannot identify jabap4 3 4,615 04-23-2015, 08:22 PM
Last Post: babu123
  Comparing webtable data with weblist and webelements in other webpage arnav 1 5,810 04-18-2014, 10:01 PM
Last Post: Parke
  Comparing two excel Sheets whose columns names vary Divya Roopa 2 8,636 03-26-2014, 07:20 PM
Last Post: Parke

Forum Jump:


Users browsing this thread: 2 Guest(s)