SubFolders Property

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The SubFolders property returns an aqObjIterator object that lists all the subfolders of the given folder. If the folder does not contain any subfolders, the property returns an empty value.

Declaration

aqFolderInfoObj.SubFolders

Read-Only Property The aqObjIterator object.
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

The aqObjIterator object whose items are aqFolderInfo objects that correspond to the subfolders of the given folder. If the specified folder does not contain subfolders, the property returns an empty value (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript).

Example

The code below posts the names of all subfolders of the C:\MyFolder folder to the test log.

JavaScript

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

  // Obtains information about the folder
  let FolInfo = aqFileSystem.GetFolderInfo(sPath);

  // Obtains the collection of subfolders
  let colSubFolders = FolInfo.SubFolders;

  // Checks whether the collection is not empty
  if (!strictEqual(colSubFolders, null))

  {
    // Posts the names of the folder's subfolders to the test log
    Log.AppendFolder("The " + sPath + " folder contains the following subfolders:");
    while (colSubFolders.HasNext())
    {
      // Obtains the current subfolder
      var FolItem = colSubFolders.Next();
      // Posts the subfolder's name to the test log
      Log.Message(FolItem.Name);
    }
    Log.PopLogFolder();

  }
  else
    Log.Message("The specified folder does not contain any subfolders.");

}

JScript

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

  // Obtains information about the folder
  var FolInfo = aqFileSystem.GetFolderInfo(sPath);

  // Obtains the collection of subfolders
  var colSubFolders = FolInfo.SubFolders;

  // Checks whether the collection is not empty
  if (colSubFolders != null)

  {
    // Posts the names of the folder's subfolders to the test log
    Log.AppendFolder("The " + sPath + " folder contains the following subfolders:");
    while (colSubFolders.HasNext())
    {
      // Obtains the current subfolder
      var FolItem = colSubFolders.Next();
      // Posts the subfolder's name to the test log
      Log.Message(FolItem.Name);
    }
    Log.PopLogFolder();

  }
  else
    Log.Message("The specified folder does not contain any subfolders.");

}

Python

def SubFoldersFinder():
  # Specifies the path to the desired folder 
  sPath = "C:\\MyFolder"
  # Obtains information about the folder 
  FolInfo = aqFileSystem.GetFolderInfo(sPath)
  # Obtains the collection of subfolders 
  colSubFolders = FolInfo.SubFolders
  # Checks whether the collection is not empty 
  if colSubFolders != None:
    # Posts the names of the folder's subfolders to the test log 
    Log.AppendFolder("The " + sPath + " folder contains the following subfolders:")
    while colSubFolders.HasNext():
      # Obtains the current subfolder 
      FolItem = colSubFolders.Next()
      # Posts the subfolder's name to the test log 
      Log.Message(FolItem.Name)
    Log.PopLogFolder()
  else:
    Log.Message("The specified folder does not contain any subfolders.")

VBScript

Sub SubFoldersFinder

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

  ' Obtains information about the folder
  Set FolInfo = aqFileSystem.GetFolderInfo(sPath)

  ' Obtains the collection of subfolders
  Set colSubFolders = FolInfo.SubFolders

  ' Checks whether the collection is not empty
  If Not colSubFolders Is Nothing Then

    ' Posts the names of the folder's subfolders to the test log
    Log.AppendFolder("The " & sPath & " folder contains the following subfolders:")
    While colSubFolders.HasNext
      ' Obtains the current subfolder
      Set FolItem = colSubFolders.Next
      ' Posts the subfolder's name to the test log
      Log.Message(FolItem.Name)
      WEnd
    Log.PopLogFolder

  Else
    Log.Message("The specified folder does not contain any subfolders.")
  End If

End Sub

DelphiScript

procedure SubFoldersFinder();
var sPath, FolInfo, colSubFolders, FolItem;
begin
  // Specifies the path to the desired folder
  sPath := 'C:\MyFolder';

  // Obtains information about the folder
  FolInfo := aqFileSystem.GetFolderInfo(sPath);

  // Obtains the collection of subfolders
  colSubFolders := FolInfo.SubFolders;

  // Checks whether the collection is not empty
  if colSubFolders <> nil then

  begin
    // Posts the names of the folder's subfolders to the test log
    Log.AppendFolder('The ' + sPath + ' folder contains the following subfolders:');
    while colSubFolders.HasNext do
    begin
      // Obtains the current subfolder
      FolItem := colSubFolders.Next;
      // Posts the subfolder's name to the test log
      Log.Message(FolItem.Name);
    end;
    Log.PopLogFolder;

  end
  else
    Log.Message('The specified folder does not contain any subfolders.');

end;

C++Script, C#Script

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

  // Obtains information about the folder
  var FolInfo = aqFileSystem["GetFolderInfo"](sPath);

  // Obtains the collection of subfolders
  var colSubFolders = FolInfo["SubFolders"];

  // Checks whether the collection is not empty
  if (colSubFolders != null)

  {
    // Posts the names of the folder's subfolders to the test log
    Log["AppendFolder"]("The " + sPath + " folder contains the following subfolders:");
    while (colSubFolders["HasNext"]())
    {
      // Obtains the current subfolder
      var FolItem = colSubFolders["Next"]();
      // Posts the subfolder's name to the test log
      Log["Message"](FolItem.Name);
    }
    Log["PopLogFolder"]();

  }
  else
    Log["Message"]("The specified folder does not contain any subfolders.");

}

See Also

Working With Files From Scripts
GetFolderInfo Method
aqObjIterator Object
Files Property

Highlight search results