aqFileSystem.FindFiles Method

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

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

Declaration

aqFileSystem.FindFiles(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 files 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 aqFileInfo objects that store information about the matching files. If no matching files 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 file, you can call the iterator’s Next or Item method and use the properties of the returned aqFileInfo object.

Example

The following code snippet demonstrates how to use this method. It searches for all EXE files in the C:\Work folder.

JavaScript

function FileFinder()
{
  var foundFiles, aFile;
  foundFiles = aqFileSystem.FindFiles("C:\\Work\\", "*.exe");
  if (!strictEqual(foundFiles, null))
    while (foundFiles.HasNext())
    {
      aFile = foundFiles.Next();
      Log.Message(aFile.Name);
    }
  else
    Log.Message("No files were found.");
}

JScript

function FileFinder()
{
  var foundFiles, aFile;
  foundFiles = aqFileSystem.FindFiles("C:\\Work\\", "*.exe");
  if (foundFiles != null)
    while (foundFiles.HasNext())
    {
      aFile = foundFiles.Next();
      Log.Message(aFile.Name);
    }
  else
    Log.Message("No files were found.");
}

Python

def FileFinder():
  foundFiles = aqFileSystem.FindFiles("C:\\Work\\", "*.exe")
  if foundFiles != None:
    while foundFiles.HasNext():
      aFile = foundFiles.Next()
      Log.Message(aFile.Name)
  else:
    Log.Message("No files were found.")

VBScript

Sub FileFinder
  Set foundFiles = aqFileSystem.FindFiles("C:\Work\", "*.exe")
  If Not foundFiles Is Nothing Then
     While foundFiles.HasNext
       Set aFile = foundFiles.Next
       Log.Message aFile.Name
     Wend
  Else
      Log.Message "No files were found."
  End If
End Sub

DelphiScript

procedure FileFinder;
var foundFiles, aFile;
begin
  foundFiles := aqFileSystem.FindFiles('C:\Work\', '*.exe');
  if foundFiles <> nil then
    while foundFiles.HasNext do
    begin
      aFile := foundFiles.Next;
      Log.Message(aFile.Name);
    end
  else
    Log.Message('No files were found.');
end;

C++Script, C#Script

function FileFinder()
{
  var foundFiles, aFile;
  foundFiles = aqFileSystem["FindFiles"]("C:\\Work\\", "*.exe");
  if (foundFiles != null)
    while (foundFiles["HasNext"]())
    {
      aFile = foundFiles["Next"]();
      Log["Message"](aFile["Name"]);
    }
  else
    Log["Message"]("No files were found.");
}

See Also

Working With Files From Scripts
aqObjIterator Object
aqFileInfo Object
FindFolders Method

Highlight search results