aqFileInfo Object

Applies to TestComplete 15.0, last modified on November 17, 2021

Description

The aqFileInfo object provides various information about a file. You can get this object in your tests using the following methods:

Members

Example

The code below checks file availability. If the file exists, the Hello, World! text line will be added to its contents. Otherwise, the script will throw an exception.

JavaScript

function aqFileInfoExample()
{
 let sPath = "C:\\FileName.txt";
 try 
 {
    //Checks whether the desired file exists
  if (aqFileSystem.GetFileInfo(sPath).Exists)
  {
    aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!!", aqFile.ctANSI);
  }
 }
 catch(e)
 {
    // Posts an error message to the test log
   Log.Error(e.message);
 }
}

JScript

function aqFileInfoExample()
{
 var sPath = "C:\\FileName.txt";
 try 
 {
    //Checks whether the desired file exists
  if (aqFileSystem.GetFileInfo(sPath).Exists)
  {
    aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!!", aqFile.ctANSI);
  }
 }
 catch(e)
 {
    // Posts an error message to the test log
   Log.Error(e.description);
 }
}

Python

def aqFileInfoExample():
  sPath = "C:\\MyFiles\\FileName.txt"
  try:
    # Checks whether the desired file exists
    if aqFileSystem.GetFileInfo(sPath).Exists:
      # Writes text to the file
      aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!!", aqFile.ctANSI)
  except Exception as e:
    Log.Error("The file has been deleted or removed.")

VBScript

Sub aqFileInfoExample
  Dim sPath, File
  sPath = "C:\asdf\vvasdasd.txt"
  Err.Clear
  On Error Resume Next
    ' Checks whether the desired file exists
    Set File = aqFileSystem.GetFileInfo(sPath)
    If aqFileSystem.GetFileInfo(sPath).Exists Then
    ' Writes text to the file
     Call aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!", aqFile.ctANSI)
    End If 
  If Err.Number <> 0 Then
    ' Posts an error message to the test log
    Log.Error Err.Description
  End If
End Sub

DelphiScript

function aqFileInfoExample;
var sPath;

begin

 sPath := 'C:\FileName.txt';
 
 try
 // Checks whether the desired file exists
 if aqFileSystem.GetFileInfo(sPath).Exists then
    // Writes text to the file
    aqFileSystem.GetFileInfo(sPath).WriteToTextFile('Hello, World!', aqFile.ctANSI);
 
 except
    // Posts an error message to the test log
    Log.Error(ExceptionMessage);
 end;
end;

C++Script, C#Script

function aqFileInfoExample()
{
 var sPath = "C:\\FileName.txt";
 try
 {
    // Checks whether the desired file exists
    if (aqFileSystem["GetFileInfo"](sPath)["Exists"])
    {
      // Writes text to the file
      aqFileSystem["GetFileInfo"](sPath)["WriteToTextFile"]( "Hello, World!!", aqFile["ctANSI"] );
    }
 }
 
 catch(e)
 {
    // Posts an error message to the test log
    Log["Error"](e["description"]);
 }
}

See Also

Working With Files From Scripts
GetFileInfo Method
FindFiles Method
aqFileSystem Object
aqObjIterator Object

Highlight search results