Files Object

Applies to TestComplete 12.60, last modified on September 17, 2018

Description

The Files object allows you to manage and process files of all types (text, graphic, HTML, etc.) stored in the Files section of the Stores collection from your scripts. For example, you can add a file to the collection, compare two files, update the file and so on. This is crucial for checking one test output file against the desired output.

The Files object contains properties that correspond to the files added to the Stores | Files collection. The property names coincide with the names of the files. Each property returns a File object that corresponds to the appropriate file. For instance, the following code provides access to the TextFile1 element:

JavaScript, JScript

var FileObj1 = Files.TextFile1;

Python

FileObj1 = Files.TextFile1

VBScript

Set FileObj1 = Files.TextFile1

DelphiScript

var
  FileObj1 : OleVariant;
begin
  FileObj1 := Files.TextFile1;
end;

C++Script, C#Script

var FileObj1 = Files["TextFile1"];

If a file is listed in the Stores | Files collection, you can specify only the file name (without the path) as a parameter for the Files object's methods.

Requirements

The Files object is available only if your project contains the Stores | Files collection.

Members

Example

The following code snippet demonstrates how you can calculate the amount of dissimilarity between two files (using the Files.CalculateHashValue method) and later compare the files using this value (using the Files.Compare method).

JavaScript, JScript

var PrecalculatedDifference;

  PrecalculatedDifference = Files.CalculateHashValue("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt");
  ...
  if (!Files.Compare("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference))
    Log.Warning("List of orders was changed");

Python

PrecalculatedDifference = Files.CalculateHashValue("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt")
# ...
if not Files.Compare("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference):
  Log.Warning("List of orders was changed")

VBScript

  PrecalculatedDifference = Files.CalculateHashValue("C:\Work\OrdersList_Var1.txt", "C:\Work\OrdersList_Var2.txt")
  ...
  If (Not Files.Compare("C:\Work\OrdersList_Var1.txt", "C:\Work\OrdersList.txt", PrecalculatedDifference)) Then 
    Log.Warning("List of orders was changed")
  End If 

DelphiScript

var PrecalculatedDifference : integer;
begin 
  PrecalculatedDifference := Files.CalculateHashValue('C:\Work\OrdersList_Var1.txt', 'C:\Work\OrdersList_Var2.txt');
  ...
  if (not Files.Compare('C:\Work\OrdersList_Var1.txt', 'C:\Work\OrdersList.txt', PrecalculatedDifference))
    then Log.Warning('List of orders was changed');
end;

C++Script, C#Script

var PrecalculatedDifference;

  PrecalculatedDifference = Files["CalculateHashValue"]("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList_Var2.txt");
  ...
  if (!Files["Compare"]("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt", PrecalculatedDifference))
    Log["Warning"]("List of orders was changed");

See Also

Regions Object
Objects Object
Stores
About Files Editor
Working With Files From Scripts

Highlight search results