aqFileSystem.GetFileInfo Method

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

Description

The GetFileInfo method returns an aqFileInfo object that contains detailed information about the specified file: attributes, size, date of creation, modification, last access and so on.

Declaration

aqFileSystem.GetFileInfo(Path)

Path [in]    Required    String    
Result The aqFileInfo object.

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Path

Specifies the path to the desired file.

Result Value

An aqFileInfo object that contains complete information about the given file.

Remarks

If the specified file does not exist, an error occurs.

Example

The code below obtains information on the specified file and posts the date when the file was created and the dates when it was last accessed and modified to the test log. If the GetFileInfo method is unable to access the specified file, an error message is posted to the test log.

JavaScript

function aqFileInfoExample()
{
  let sPath = "C:\\MyFiles\\FileName.txt";

  try
  {
    // Obtains the object that holds information about the specified file
    let Info = aqFileSystem.GetFileInfo(sPath);
    // Posts the dates when the file was created, modified and accessed to the test log
    Log.Message("Created: " + aqConvert.DateTimeToStr(Info.DateCreated));
    Log.Message("Modified: " + aqConvert.DateTimeToStr(Info.DateLastModified));
    Log.Message("Accessed: " + aqConvert.DateTimeToStr(Info.DateLastAccessed));
    }

  catch(e)
    {
    // Posts an error message to the test log
    Log.Error(e.message);
  }
}

JScript

function aqFileInfoExample()
{
  var sPath = "C:\\MyFiles\\FileName.txt";

  try
  {
    // Obtains the object that holds information about the specified file
    var Info = aqFileSystem.GetFileInfo(sPath);
    // Posts the dates when the file was created, modified and accessed to the test log
    Log.Message("Created: " + aqConvert.DateTimeToStr(Info.DateCreated));
    Log.Message("Modified: " + aqConvert.DateTimeToStr(Info.DateLastModified));
    Log.Message("Accessed: " + aqConvert.DateTimeToStr(Info.DateLastAccessed));
    }

  catch(e)
    {
    // Posts an error message to the test log
    Log.Error(e.description);
  }
}

Python

def aqFileInfoExample():
  sPath = "C:\\MyFiles\\File.txt"
  try:
    # Obtains the object that holds information about the specified file
    Info = aqFileSystem.GetFileInfo(sPath);
    # Posts the dates when the file was created, modified and accessed to the test log
    Log.Message("Created: " + aqConvert.DateTimeToStr(Info.DateCreated))
    Log.Message("Modified: " + aqConvert.DateTimeToStr(Info.DateLastModified))
    Log.Message("Accessed: " + aqConvert.DateTimeToStr(Info.DateLastAccessed))
  except Exception as e:
    # Posts an error message to the test log
    Log.Error(e.description)

VBScript

Sub aqFileInfoExample
  Dim sPath, Info
  sPath = "C:\MyFiles\FileName.txt"

  Err.Clear
  On Error Resume Next
    ' Obtains the object that holds information about the specified file
    Set Info = aqFileSystem.GetFileInfo(sPath)
    ' Posts the dates when the file was created, modified and accessed to the test log
    Log.Message("Created: " & aqConvert.DateTimeToStr(Info.DateCreated))
    Log.Message("Modified: " & aqConvert.DateTimeToStr(Info.DateLastModified))
    Log.Message("Accessed: " & aqConvert.DateTimeToStr(Info.DateLastAccessed))
    

  If Err.Number <> 0 Then
    ' Posts an error message to the test log
    Log.Error Err.Description
  End If
End Sub

DelphiScript

procedure aqFileInfoExample();
var
sPath: string;
Info : OleVariant;

begin
  sPath := 'C:\MyFiles\FileName.txt';

  try
    // Obtains the object that holds information about the specified file
    Info := aqFileSystem.GetFileInfo(sPath);
    // Posts the dates when the file was created, modified and accessed to the test log
    Log.Message('Created: ' + aqConvert.DateTimeToStr(Info.DateCreated));
    Log.Message('Modified: ' + aqConvert.DateTimeToStr(Info.DateLastModified));
    Log.Message('Accessed: ' + aqConvert.DateTimeToStr(Info.DateLastAccessed));
    

  except
    // Posts an error message to the test log
    Log.Error(ExceptionMessage);
  end;
end;

C++Script, C#Script

function aqFileInfoExample()
{
  var sPath = "C:\\MyFiles\\FileName.txt";

  try
  {
    // Obtains the object that holds information about the specified file
    var Info = aqFileSystem["GetFileInfo"](sPath);
    // Posts the dates when the file was created, modified and accessed to the test log
    Log["Message"]("Created: " + aqConvert.DateTimeToStr(Info["DateCreated"]));
    Log["Message"]("Modified: " + aqConvert.DateTimeToStr(Info["DateLastModified"]));
    Log["Message"]("Accessed: " + aqConvert.DateTimeToStr(Info["DateLastAccessed"]));
    }

  catch(e)
    {
    // Posts an error message to the test log
    Log["Error"](e["description"]);
  }
}

See Also

Working With Files From Scripts
aqFileInfo Object

Highlight search results