Compare Method

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

Use the Compare method to compare the file described by the aqFileInfoObj object with another file specified by the PathToFile2 parameter.

Declaration

aqFileInfoObj.Compare(PathToFile2)

aqFileInfoObj An expression, variable or parameter that specifies a reference to an aqFileInfo object
PathToFile2 [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile2

Specifies the fully qualified path to the file with which the target file will be compared.

Result Value

True if the specified files are identical, and False otherwise.

Example

The code below compares two files and posts either an informative message to the test log, if the files are identical, or an error message, if the files are not identical.

JavaScript, JScript

function aqFileInfoCompare()
{
  var sPath1 = "C:\\MyFiles\\File1.txt";
  var sPath2 = "C:\\Work\\File2.txt";
  
  // Compares the files
  var Res = aqFileSystem.GetFileInfo(sPath1).Compare(sPath2);
  
  // Posts results to the test log
  if (Res)
   Log.Message("The files are idential.")
  else
   Log.Error("The files are not identical.")
  
}

Python

def aqFileInfoCompare():
  sPath1 = "C:\\MyFiles\\File1.txt"
  sPath2 = "C:\\Work\\File2.txt"
  # Compares the files
  Res = aqFileSystem.GetFileInfo(sPath1).Compare(sPath2)
  # Posts results to the test log
  if Res: 
   Log.Message("The files are idential.")
  else:
   Log.Error("The files are not identical.")

VBScript

Sub aqFileInfoCompare

  sPath1 = "C:\MyFiles\File1.txt"
  sPath2 = "C:\Work\File2.txt"
  
  ' Compares the files
  Set Res = aqFileSystem.GetFileInfo(sPath1).Compare(sPath2)
  
  ' Posts results to the test log
  If Res Then 
   Log.Message("The files are idential.")
  else 
   Log.Error("The files are not identical.")
  End If
  
End Sub

DelphiScript

function aqFileInfoCompare;
var sPath1, sPath2, Res;
begin
  sPath1 := 'C:\MyFiles\File1.txt';
  sPath2 := 'C:\Work\File2.txt';
  
  // Compares the files
  Res := aqFileSystem.GetFileInfo(sPath1).Compare(sPath2);
  
  // Posts results to the test log
  If Res Then
   Log.Message('The files are idential.')
  else
   Log.Error('The files are not identical.')
  
end;

C++Script, C#Script

function aqFileInfoCompare()
{
  var sPath1 = "C:\\MyFiles\\File1.txt";
  var sPath2 = "C:\\Work\\File2.txt";
  
  // Compares the files
  var Res = aqFileSystem["GetFileInfo"](sPath1)["Compare"](sPath2);
  
  // Posts results to the test log
  if (Res)
   Log["Message"]("The files are idential.")
  else
   Log["Error"]("The files are not identical.")
  
}

See Also

Working With Files From Scripts
Copy Method
Rename Method
Move Method

Highlight search results