Files Property

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

Description

The Files property returns an aqObjIterator object that lists all the files stored in the given folder. If no files are stored in the folder, the property returns an empty value.

Declaration

aqFolderInfoObj.Files

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 aqFileInfo objects that correspond to the files stored in the given folder. If the specified folder does not contain any files, the property returns an empty value (Nothing in VBScript, nil in DelphiScript, None in Python and null in JavaScript, JScript, C++Script and C#Script).

Example

The code below searches for all TXT files in the C:\MyFiles folder and posts their names to the test log.

JavaScript

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

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

  // Checks whether the folder stores any files
  if (!strictEqual(colFiles, null))
  {
    // Iterates through the collection of files stored in the folder
    while (colFiles.HasNext())
    {
      // Obtains a file stored in the folder
      let FileItem = colFiles.Next();

      // Obtains the file's extension and checks whether the extension is txt
      FileExt = aqFileSystem.GetFileExtension(FileItem.Path);
      if (equal(FileExt, "txt"))
        // Posts the file name to the test log
        Log.Message(FileItem.Name);
    }
  }

  else
    Log.Message("The " + sPath + " folder does not store any files");

}

JScript

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

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

  // Checks whether the folder stores any files
  if (colFiles != null)
  {
    // Iterates through the collection of files stored in the folder
    while (colFiles.HasNext())
    {
      // Obtains a file stored in the folder
      var FileItem = colFiles.Next();

      // Obtains the file's extension and checks whether the extension is txt
      FileExt = aqFileSystem.GetFileExtension(FileItem.Path)
      if (FileExt == "txt")
        // Posts the file name to the test log
        Log.Message(FileItem.Name);
    }
  }

  else
    Log.Message("The " + sPath + " folder does not store any files");

}

Python

def FilesFinderExample():
  # Specifies the path to the desired folder 
  sPath = "C:\\MyFiles"
  # Obtains information about the folder 
  colFiles = aqFileSystem.GetFolderInfo(sPath).Files
  # Checks whether the folder stores any files 
  if colFiles != None:
    # Iterates through the collection of files stored in the folder 
    while colFiles.HasNext():
      # Obtains a file stored in the folder 
      FileItem = colFiles.Next()
      # Obtains the file's extension and checks whether the extension is txt 
      FileExt = aqFileSystem.GetFileExtension(FileItem.Path)
      if FileExt == "txt":
        # Posts the file name to the test log 
        Log.Message(FileItem.Name)
  else:
    Log.Message("The " + sPath + " folder does not store any files")

VBScript

Sub FilesFinderExample

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

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

  ' Checks whether the folder stores any files
  If Not colFiles Is Nothing Then

    ' Iterates through the collection of files stored in the folder
    While colFiles.HasNext

      ' Obtains a file stored in the folder
      Set FileItem = colFiles.Next

      ' Obtains the file's extension and checks whether the extension is txt
      FileExt = aqFileSystem.GetFileExtension(FileItem.Path)
      If FileExt = "txt" Then
        ' Posts the file name to the test log
        Log.Message(FileItem.Name)
      End If
    Wend

  Else
    Log.Message("The " & sPath & " folder does not store any files")
  End If

End Sub

DelphiScript

procedure FilesFinderExample();
var sPath, colFiles, FileItem, FileExt;
begin
  // Specifies the path to the desired folder
  sPath := 'C:\MyFiles';

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

  // Checks whether the folder stores any files
  if colFiles <> nil then
  begin
    // Iterates through the collection of files stored in the folder
    while colFiles.HasNext do
    begin
      // Obtains a file stored in the folder
      FileItem := colFiles.Next;

      // Obtains the file's extension and checks whether the extension is txt
      FileExt := aqFileSystem.GetFileExtension(FileItem.Path);
      if FileExt = 'txt' then
        // Posts the file name to the test log
        Log.Message(FileItem.Name);
    end;
  end

  else
    Log.Message('The ' + sPath + ' folder does not store any files');

end;

C++Script, C#Script

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

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

  // Checks whether the folder stores any files
  if (colFiles != null)
  {
    // Iterates through the collection of files stored in the folder
    while (colFiles["HasNext"]())
    {
      // Obtains a file stored in the folder
      var FileItem = colFiles["Next"]();

      // Obtains the file's extension and checks whether the extension is txt
      FileExt = aqFileSystem["GetFileExtension"](FileItem["Path"])
      if (FileExt == "txt")
        // Posts the file name to the test log
        Log["Message"](FileItem["Name"]);
    }
  }

  else
    Log["Message"]("The " + sPath + " folder does not store any files");

}

See Also

Working With Files From Scripts
GetFolderInfo Method
aqObjIterator Object
SubFolders Property

Highlight search results