aqFileSystem.FindFolders Method

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

Description

Use the FindFolders method to search the specified folder for all the subfolders matching the given pattern. To search for files of a given folder, use the FindFiles method.

Declaration

aqFileSystem.FindFolders(PathSearchPatternSearchInSubDirs)

Path [in]    Required    String    
SearchPattern [in]    Required    String    
SearchInSubDirs [in]    Optional    Boolean Default value: False   
Result The aqObjIterator object.

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Path

Specifies the location (the fully qualified path) where the search will be performed.

The Path parameter may or may not include a trailing backslash (\). You can add a trailing backslash to or remove it from the path by using the IncludeTrailingBackSlash or ExcludeTrailingBackSlash method.

SearchPattern

Specifies the names of the folders to search. A name can include the * and ? wildcard characters. An asterisk corresponds to a string of any length, a question mark - to any single character.

SearchInSubDirs

Specifies whether to perform the search in the subfolders of the folder specified by the Path parameter.

If SearchInSubDirs is False, which is the default value, no search in subfolders is performed. Otherwise, the method performs the search both in a specified folder and in its subfolders.

Result Value

The aqObjIterator object whose items are aqFolderInfo objects that store information about the matching folders. If no matching folders were found, the method returns an empty object (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript).

To get information about an individual folder, you can call the iterator’s Next or Item method and use the properties of the returned aqFolderInfo object.

Example

The following code snippet demonstrates how to use this method. It searches for the folders that contain the Work string in their names and are located on the D drive.

JavaScript

function FolderFinder()
{
  var foundFolders, aFolder;
  foundFolders = aqFileSystem.FindFolders("D:\\", "*Work*");
  if (!strictEqual(foundFolders, null))
    while (foundFolders.HasNext())
    {
      aFolder = foundFolders.Next();
      Log.Message(aFolder.Path);
    }
  else
    Log.Message("No folders were found.");
}

JScript

function FolderFinder()
{
  var foundFolders, aFolder;
  foundFolders = aqFileSystem.FindFolders("D:\\", "*Work*");
  if (foundFolders != null)
    while (foundFolders.HasNext())
    {
      aFolder = foundFolders.Next();
      Log.Message(aFolder.Path);
    }
  else
    Log.Message("No folders were found.");
}

Python

def FolderFinder():
  foundFolders = aqFileSystem.FindFolders("D:\\", "*Work*")
  if foundFolders != None:
    while foundFolders.HasNext():
      aFolder = foundFolders.Next()
      Log.Message(aFolder.Path)
  else:
    Log.Message("No folders were found.")

VBScript

Sub FolderFinder
  Set foundFolders = aqFileSystem.FindFolders("D:\", "*Work*")
  If Not foundFolders Is Nothing Then
     While foundFolders.HasNext
       Set aFolder = foundFolders.Next
       Log.Message aFolder.Path
     Wend
  Else
      Log.Message "No folders were found."
  End If
End Sub

DelphiScript

procedure FolderFinder;
var foundFolders, aFolder;
begin
  foundFolders := aqFileSystem.FindFolders('D:\', '*Work*');
  if foundFolders <> nil then
    while foundFolders.HasNext do
    begin
      aFolder := foundFolders.Next;
      Log.Message(aFolder.Path);
    end
  else
    Log.Message('No folders were found.');
end;

C++Script, C#Script

function FolderFinder()
{
  var foundFolders, aFolder;
  foundFolders = aqFileSystem["FindFolders"]("D:\\", "*Work*");
  if (foundFolders != null)
    while (foundFolders["HasNext"]())
    {
      aFolder = foundFolders["Next"]();
      Log["Message"](aFolder["Path"]);
    }
  else
    Log["Message"]("No folders were found.");
}

See Also

Working With Files From Scripts
aqObjIterator Object
aqFolderInfo Object
aqFileSystem.FindFiles Method

Highlight search results