Exists Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The Exists property returns True if the folder corresponding to the given aqFolderInfoObj object exists. Otherwise, the property returns False.

Declaration

aqFolderInfoObj.Exists

Read-Only Property Boolean
aqFolderInfoObj An expression, variable or parameter that specifies a reference to an aqFolderInfo object

Applies To

The property is applied to the following object:

Property Value

True if the folder exists, and False if it does not.

Remarks

If you try to obtain the aqFolderInfo object for a folder that does not exist, an error will occur.

Example

The routine below creates a folder and obtains the object that holds information on the created folder. Then the routine performs actions over the folder and checks whether the created folder still exists. If it does, the routine adds a file to the folder. Otherwise, an error occurs.

JavaScript

function FolderExistsExample()
{
  // Specifies the path to the desired folder
  let sPath = "C:\\MyFolder";

  // Creates a folder
  aqFileSystem.CreateFolder(sPath);

  try
  {
    // Obtains information on the folder
    let FolderInfo = aqFileSystem.GetFolderInfo(sPath);

    // Performs actions over the folder
    …

    // Checks whether the folder still exists
    if (FolderInfo.Exists)
      // Adds a file to the specified folder
      aqFile.Create(sPath + "\\MyFile.txt");

    else
      Log.Error("The folder "+ sPath + " does not exist");
  }
  catch (e)
  {
    Log.Error(e.message);
  }

}

JScript

function FolderExistsExample()
{
  // Specifies the path to the desired folder
  var sPath = "C:\\MyFolder";

  // Creates a folder
  aqFileSystem.CreateFolder(sPath);

  try
  {
    // Obtains information on the folder
    var FolderInfo = aqFileSystem.GetFolderInfo(sPath);

    // Performs actions over the folder
    …

    // Checks whether the folder still exists
    if (FolderInfo.Exists)
      // Adds a file to the specified folder
      aqFile.Create(sPath + "\\MyFile.txt");

    else
      Log.Error("The folder "+ sPath + " does not exist");
  }
  catch (e)
  {
    Log.Error(e.description);
  }

}

Python

def FolderExistsExample():
  # Specifies the path to the desired folder 
  sPath = "C:\\MyFolder"
  # Creates a folder 
  aqFileSystem.CreateFolder(sPath)
  try:
    # Obtains information on the folder
    FolderInfo = aqFileSystem.GetFolderInfo(sPath)
    # Performs actions over the folder 
    # ...
    # Checks whether the folder still exists 
    if FolderInfo.Exists:
      # Adds a file to the specified folder 
      aqFile.Create(sPath + "\\MyFile.txt")
    else:
      Log.Error("The folder "+ sPath + " does not exist")
  except Exception as e:
    Log.Error(e.description)

VBScript

Sub FolderExistsExample

  Dim sPath, FolderInfo

  ' Specifies the path to the desired folder
  sPath = "C:\MyFolder"

  ' Creates a folder
  aqFileSystem.CreateFolder(sPath)

  ' Obtains information on the folder
  Err.Clear

  On Error Resume Next
  Set FolderInfo = aqFileSystem.GetFolderInfo(sPath)

  If Err.Number <> 0 Then
    Log.Error Err.Description

  Else
    ' Performs actions over the folder
    …

    ' Checks whether the folder still exists
    If FolderInfo.Exists Then

      ' Adds a file to the specified folder
      aqFile.Create(sPath & "\MyFile.txt")

    Else
      Log.Error("The folder " & sPath & " does not exist")
    End If

  End If

End Sub

DelphiScript

procedure FolderExistsExample();
var sPath, FolderInfo;
begin
  // Specifies the path to the desired folder
  sPath := 'C:\MyFolder';

  // Creates a folder
  aqFileSystem.CreateFolder(sPath);

  try
    // Obtains information on the folder
    FolderInfo := aqFileSystem.GetFolderInfo(sPath);

    // Performs actions over the folder
    …

    // Checks whether the folder still exists
    if FolderInfo.Exists then
      // Adds a file to the specified folder
      aqFile.Create(sPath + '\MyFile.txt')

    else
      Log.Error('The folder '+ sPath + ' does not exist');
  except
    Log.Error(ExceptionMessage);
  end;

end;

C++Script, C#Script

function FolderExistsExample()
{
  // Specifies the path to the desired folder
  var sPath = "C:\\MyFolder";

  // Creates a folder
  aqFileSystem["CreateFolder"](sPath);

  try
  {
    // Obtains information on the folder
    var FolderInfo = aqFileSystem["GetFolderInfo"](sPath);

    // Performs actions over the folder
    …

    // Checks whether the folder still exists
    if (FolderInfo["Exists"])
      // Adds a file to the specified folder
      aqFile["Create"](sPath + "\\MyFile.txt");

    else
      Log["Error"]("The folder "+ sPath + " does not exist");
  }
  catch (e)
  {
    Log["Error"](e["description"]);
  }

}

See Also

Working With Files From Scripts
aqFileSystem.GetFolderInfo Method
Name Property
Path Property

Highlight search results