ReadAll Method

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

Description

The ReadAll method returns a string that contains the content of a text file.

Declaration

aqTextFileObj.ReadAll()

aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object
Result String

Applies To

The method is applied to the following object:

Result Value

A string holding the text of a file.

Remarks

On success, the cursor position is moved to the end of the file.

Example

The code below opens the specified file for reading, reads all its content and posts it to the test log.

JavaScript, JScript

function ReadAllFile()
{
  var sPath = "D:\\Files\\MyFile.txt";

   // Opens the specified file for reading
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);
  
  // Obtains the file content
  var sFile = myFile.ReadAll();
  // Posts the file content to the test log
  Log.Message(sFile);
  
  // Closes the file
  myFile.Close();
}

Python

def ReadAllFile():
  sPath = "D:\\Files\\MyFile.txt"
  # Opens the specified file for reading
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)
  # Obtains the file content
  sFile = myFile.ReadAll()
  # Posts the file content to the test log
  Log.Message(sFile)
  # Closes the file 
  myFile.Close()

VBScript

Sub ReadAllFile
  sPath = "D:\Files\MyFile.txt"

   ' Opens the specified file for reading
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)
  
  ' Obtains the file content
  sFile = myFile.ReadAll
  ' Posts the file content to the test log
  Log.Message(sFile)
  
  ' Closes the file
  myFile.Close()
End Sub

DelphiScript

function ReadAllFile;
var sPath, myFile, sFile;
begin
  sPath := 'D:\Files\MyFile.txt';

   // Opens the specified file for reading
  myFile := aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);
  
  // Obtains the file content
  sFile := myFile.ReadAll;
  // Posts the file content to the test log
  Log.Message(sFile);
  
  // Closes the file
  myFile.Close();
end;

C++Script, C#Script

function ReadAllFile()
{
  var sPath = "D:\\Files\\MyFile.txt";

   // Opens the specified file for reading
  var myFile = aqFile["OpenTextFile"]( sPath, aqFile["faRead"], aqFile["ctANSI"] );
  
  // Obtains the file content
  var sFile = myFile["ReadAll"]();
  // Posts the file content to the test log
  Log["Message"](sFile);
  
  // Closes the file
  myFile["Close"]();
}

See Also

Working With Files From Scripts
Write Method
WriteLine Method
ReadLine Method
ReadToSymbol Method
ReadString Method

Highlight search results