aqObjIterator Object

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

The aqObjIterator object provides a common interface for operations performed over several similar objects. This object is returned by a number of scripting methods and properties. The meaning of collection items depends on certain method or property. The table below lists the possible variants:

Method/Property Generator Collection Items
aqDriveInfo.Files Files from the root of the drive to which the aqDriveInfo object relates.
aqDriveInfo.Folders Folders of the drive to which the aqDriveInfo object relates.
aqFileSystem.FindFiles Files matching the specified search pattern.
aqFileSystem.FindFolders Folders matching the specified search pattern.
aqFileSystem.Drives Drives available in the system.
aqFolderInfo.Files Files of the folder to which the aqFolderInfo object relates.
aqFolderInfo.SubFolders Subfolders of the folder to which the aqFolderInfo object relates.
aqObject.GetEvents Events of the source object represented by a certain aqObject instance.
aqObject.GetFields Fields of the source object represented by a certain aqObject instance.
aqObject.GetMethods Methods of the source object represented by a certain aqObject instance.
aqObject.GetProperties Properties of the source object represented by a certain aqObject instance.

The object provides two ways of accessing collection items: sequential and indexed. The sequential way implies that you obtain the first item of the collection and on later iterations you can get the neighbor of the current item. Therefore, to reach item N, you should iterate through N-1 items that precede it. Using indexed access, you can obtain any item by specifying the item’s ordinal number (index). The sequential access type is convenient for complete enumeration of items, whereas the indexed access type is useful when you only need to get certain items.

The default method of the aqObjIterator object is Item. You can skip the method’s name in your script statements to make them shorter. For example, the following two script lines perform the same actions:

JavaScript, JScript

drv = aqFileSystem.Drives.Item(0);
drv = aqFileSystem.Drives(0);

Python

drv = aqFileSystem.Drives.Item(0)
drv = aqFileSystem.Drives

VBScript

drv = aqFileSystem.Drives.Item(0)
drv = aqFileSystem.Drives(0)

DelphiScript

drv := aqFileSystem.Drives.Item(0);
drv := aqFileSystem.Drives(0);

C++Script, C#Script

drv = aqFileSystem["Drives"]["Item"](0);
drv = aqFileSystem["Drives"](0);

Members

Example

The code below demonstrates how you can access all the drives existing on your computer in a sequential way and post their letters to the test log.

JavaScript, JScript

function ObtainDriveLetters()
{

  // Obtains the drives collection
  var DrvCol = aqFileSystem.Drives;
  
  while (DrvCol.HasNext() )
  {
    // Obtains the current drive
    var DrvItem = DrvCol.Next();
    // Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter);
  }
    
}

Python

def ObtainDriveLetters():
  # Obtains the drives collection
  DrvCol = aqFileSystem.Drives
  while DrvCol.HasNext():
    # Obtains the current drive
    DrvItem = DrvCol.Next()
    # Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter)

VBScript

Sub ObtainDriveLetters

  ' Obtains the drives collection
  Set DrvCol = aqFileSystem.Drives
  
  While DrvCol.HasNext
    ' Obtains the current drive
    Set DrvItem = DrvCol.Next
    ' Posts the drive letter to the test log
    Log.Message DrvItem.DriveLetter
  WEnd
    
End Sub

DelphiScript

function ObtainDriveLetters;
var DrvCol, DrvItem;
begin

  // Obtains the drives collection
  DrvCol := aqFileSystem.Drives;
  
  while (DrvCol.HasNext() ) do
  begin
    // Obtains the current drive
    DrvItem := DrvCol.Next();
    // Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter);
  end;
    
end;

C++Script, C#Script

function ObtainDriveLetters()
{

  // Obtains the drives collection
  var DrvCol = aqFileSystem["Drives"];
  
  while (DrvCol["HasNext"]() )
  {
    // Obtains the current drive
    var DrvItem = DrvCol["Next"]();
    // Posts the drive letter to the test log
    Log["Message"]( DrvItem["DriveLetter"] );
  }
    
}

The code below demonstrates how you can access all the drives existing on your computer in an indexed way and post their letters to the test log.

JavaScript, JScript

function ObtainDriveLetters2()
{

  // Obtains the drives collection
  var DrvCol = aqFileSystem.Drives;
  // Obtains the drives total number
  var Num = DrvCol.Count;
  
  for ( var i = 0; i< Num; i++ )
  {     // Obtains the current drive
    var DrvItem = DrvCol.Item(i);
    // Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter);
  }
    
}

Python

def ObtainDriveLetters2():
  # Obtains the drives collection
  DrvCol = aqFileSystem.Drives
  # Obtains the drives total number
  Num = DrvCol.Count
  for i in range(0, Num):
    # Obtains the current drive
    DrvItem = DrvCol.Item(i)
    # Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter)

VBScript

Sub ObtainDriveLetters2

  ' Obtains the drives collection
  Set DrvCol = aqFileSystem.Drives
  ' Obtains the drives total number
  Num = DrvCol.Count
  
  For i = 0 To Num-1
    'Obtains the current drive
    Set DrvItem = DrvCol.Item(i)
    ' Posts the drive letter to the test log
    Log.Message DrvItem.DriveLetter
  Next
    
End Sub

DelphiScript

function ObtainDriveLetters2;
var DrvCol, Num, i, DrvItem;
begin

  // Obtains the drives collection
  DrvCol := aqFileSystem.Drives;
  // Obtains the drives total number
  Num := DrvCol.Count;
  
  for i := 0 to Num-1 do
  begin    // Obtains the current drive
    DrvItem := DrvCol.Item(i);
    // Posts the drive letter to the test log
    Log.Message(DrvItem.DriveLetter);
  end;
    
end;

C++Script, C#Script

function ObtainDriveLetters2()
{

  // Obtains the drives collection
  var DrvCol = aqFileSystem["Drives"];
  // Obtains the drives total number
  var Num = DrvCol["Count"];
  
  for ( var i = 0; i< Num; i++ )
  {     // Obtains the current drive
    var DrvItem = DrvCol["Item"](i);
    // Posts the drive letter to the test log
    Log["Message"]( DrvItem["DriveLetter"] );
  }
    
}

See Also

FindFiles Method
SubFolders Property
GetEvents Method
GetFields Method
GetMethods Method
GetProperties Method

Highlight search results