'#3. To compare two given files through QTP
'Return True if files are identical. Return False if files are different.
'COMMANDS INVOLVED-
'Set fso = CreateObject("Scripting.fileSystemObject")
'Set file1 = fso.GetFile(filePath1)
'file1.Size
'Set file1Txt = file1.OpenAsTextStream
'DO WHILE file1Txt.ATENDOFSTREAM = FALSE
'str1 = file1Txt.READ(1000)
filePath1 = "U:\Automation\QTP Notes\Screen1.png"
filePath2 = "U:\Automation\QTP Notes\Screen2.png"
filePath3 = "U:\Automation\QTP Notes\Tasks.txt"
msgbox compareFiles(filePath1, filePath3)
Function compareFiles(filePath1, filePath2)
Set fso = CreateObject("Scripting.fileSystemObject")
Set file1 = fso.GetFile(filePath1)
Set file2 = fso.GetFile(filePath2)
If file1.Size <> file2.Size then
msgbox "Files are different."
else
Set file1Txt = file1.OpenAsTextStream
Set file2Txt = file2.OpenAsTextStream
compareFiles = True
DO WHILE file1Txt.ATENDOFSTREAM = FALSE
str1 = file1Txt.READ(1000)
str2 = file2Txt.READ(1000)
compareFiles = STRCOMP(Str1, Str2, 0)
If compareFiles <> 0 Then
compareFiles = False
EXIT DO
else
compareFiles = True
END IF
LOOP
End If
End Function
'Return True if files are identical. Return False if files are different.
'COMMANDS INVOLVED-
'Set fso = CreateObject("Scripting.fileSystemObject")
'Set file1 = fso.GetFile(filePath1)
'file1.Size
'Set file1Txt = file1.OpenAsTextStream
'DO WHILE file1Txt.ATENDOFSTREAM = FALSE
'str1 = file1Txt.READ(1000)
filePath1 = "U:\Automation\QTP Notes\Screen1.png"
filePath2 = "U:\Automation\QTP Notes\Screen2.png"
filePath3 = "U:\Automation\QTP Notes\Tasks.txt"
msgbox compareFiles(filePath1, filePath3)
Function compareFiles(filePath1, filePath2)
Set fso = CreateObject("Scripting.fileSystemObject")
Set file1 = fso.GetFile(filePath1)
Set file2 = fso.GetFile(filePath2)
If file1.Size <> file2.Size then
msgbox "Files are different."
else
Set file1Txt = file1.OpenAsTextStream
Set file2Txt = file2.OpenAsTextStream
compareFiles = True
DO WHILE file1Txt.ATENDOFSTREAM = FALSE
str1 = file1Txt.READ(1000)
str2 = file2Txt.READ(1000)
compareFiles = STRCOMP(Str1, Str2, 0)
If compareFiles <> 0 Then
compareFiles = False
EXIT DO
else
compareFiles = True
END IF
LOOP
End If
End Function
No comments:
Post a Comment