FileNameByName Method

Applies to TestComplete 15.46, last modified on December 01, 2022

Description

The FileNameByName method lets you obtain the full path to the file referred to by an item that has the specified name in the Files, Objects or Regions collection.

Declaration

ProgObj.FileNameByName(Name)

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

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Name

Unique name of the Stores collection's item that refers to the file whose name you want to get.

Result Value

Full path to the file referred to by an item having the specified name in the collection.

Example

The following code snippet obtains the full path to the file referred to by the specified item, opens the file and posts its data to the test log.

JavaScript, JScript

function Test1()
{
  // Obtains the full path to the file
  sPath = Files.FileNameByName("MyFile_txt");

  // Reads the data stored in this file
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead,aqFile.ctUnicode);
  Log.Message(myFile.ReadAll);
}

Python

def Test1():
  # Obtains the full path to the file 
  sPath = Files.FileNameByName("MyFile_txt")
  # Reads the data stored in this file 
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead,aqFile.ctUnicode)
  Log.Message(myFile.ReadAll)

VBScript

Sub Test1
  ' Obtains the full path to the file
  sPath = Files.FileNameByName("MyFile_txt")

  ' Reads the data stored in this file
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead,aqFile.ctUnicode)
  Log.Message(myFile.ReadAll)
End Sub

DelphiScript

procedure Test1;
begin
  // Obtains the full path to the file
  sPath := Files.FileNameByName('MyFile_txt');

  // Reads the data stored in this file
  myFile := aqFile.OpenTextFile(sPath, aqFile.faRead,aqFile.ctUnicode);
  Log.Message(myFile.ReadAll);
end;

C++Script, C#Script

function Test1() {
  // Obtains the full path to the file
  sPath = Files["FileNameByName"]("MyFile_txt");

  // Reads the data stored in this file
  myFile = aqFile["OpenTextFile"](sPath, aqFile.faRead,aqFile.ctUnicode);
  Log["Message"](myFile.ReadAll);
}

See Also

FileNameByIndex Method
NameByFileName Method
NameByIndex Method
FileNamesList Method

Highlight search results