FindFiles Method

Applies to TestComplete 15.47, last modified on January 20, 2023
The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.

Description

Use the FindFiles method to search the connected Android device or a folder on the Android device for files that match the specified pattern.

Declaration

ProgObj.FindFiles(FileMask)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
FileMask [in]    Required    String    
Result An aqObjIterator object

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

FileMask

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

The mask is case-sensitive.

Result Value

The aqObjIterator objects whose items are AndroidFile objects that store information about the matching files.

To get information on individual files, you can call the iterator’s Next and Item methods and use the properties of the returned AndroidFile object.

Example

The sample code below demonstrates how to search the system/app folder on the connected Android device for all .apk files and posts the names of the found files to the test log:

JavaScript, JScript

function Test()
{

  var fileSystemManager = Mobile.Device("MyDevice").FileSystemManager;
  var apkFiles = fileSystemManager.FindFiles("system/app/*.apk");

  if (apkFiles.Count > 0)
  {
    while (apkFiles.HasNext())
    {
      var apkFile = apkFiles.Next();
      Log.Message(apkFile.Name);
    }

  }
  else
    Log.Warning("No files were found.");

}

Python

def Test():
  fileSystemManager = Mobile.Device("MyDevice").FileSystemManager
  apkFiles = fileSystemManager.FindFiles("system/app/*.apk")

  if apkFiles.Count > 0:
    while apkFiles.HasNext:
      apkFile = apkFiles.Next
      Log.Message(apkFile.Name)
  else:
    Log.Warning("No files were found.")

VBScript

Sub Test

  Set fileSystemManager = Mobile.Device("MyDevice").FileSystemManager
  Set apkFiles = fileSystemManager.FindFiles("system/app/*.apk")

  If apkFiles.Count > 0 Then
    While apkFiles.HasNext
      Set apkFile = apkFiles.Next
      Log.Message(apkFile.Name)
    Wend

  Else
    Log.Warning("No files were found.")
  End If

End Sub

DelphiScript

procedure Test();
var fileSystemManager, apkFiles, apkFile;
begin

fileSystemManager := Mobile.Device('MyDevice').FileSystemManager;
apkFiles := fileSystemManager.FindFiles('system/app/*.apk');

if apkFiles.Count > 0 then
  begin
    while apkFiles.HasNext do
    begin
      apkFile := apkFiles.Next;
      Log.Message(apkFile.Name);
    end;

    end
else
    Log.Warning('No files were found.');

end;

C++Script, C#Script

function Test()
{

  var fileSystemManager = Mobile["Device"]("MyDevice")["FileSystemManager"];
  var apkFiles = fileSystemManager["FindFiles"]("system/app/*.apk");

  if (apkFiles["Count"] > 0)
  {
    while (apkFiles["HasNext"]())
    {
      var apkFile = apkFiles["Next"]();
      Log["Message"](apkFile["Name"]);
    }

  }
  else
    Log["Warning"]("No files were found.");

}

See Also

FileSystemManager Object
AndroidFolder Object
aqObjIterator Object
AndroidFile Object
Testing Android Applications (Legacy)

Highlight search results