Applies to TestComplete 12.20, last modified on January 17, 2017

Description

The aqFile object allows you to manage files as well as read from and write to text and binary files. This object complements the aqFileSystem object, but unlike the latter it lets you deal with files only.

Members

Example

The example below demonstrates how you can create a file and write text to it using the aqFile object.

JavaScript, JScript

function CreatingAndWritingToTextFile()
{
 if (aqFile.Create("C:\\MyFiles\\DemoFile.txt") == 0)
 {
  aqFile.WriteToTextFile("C:\\MyFiles\\DemoFile.txt", "Hello!", aqFile.ctUTF8);
  Log.Message("The file is created and the specified text is written to it successfully.");
 }
 else 
 {
  Log.Error("The file was not created.");
 }
}

Python

def CreatingAndWritingToTextFile():
  if aqFile.Create("C:\\MyFiles\\DemoFile.txt") == 0:
    aqFile.WriteToTextFile("C:\\MyFiles\\DemoFile.txt", "Hello!", aqFile.ctUTF8)
    Log.Message("The file is created and the specified text is written to it successfully.")
  else:
    Log.Error("The file was not created.")

VBScript

Sub CreatingAndWritingToTextFile

 If (aqFile.Create("C:\MyFiles\DemoFile.txt") = 0) Then
  Call aqFile.WriteToTextFile("C:\MyFiles\DemoFile.txt", "Hello!", aqFile.ctUTF8)
  Call Log.Message("The file is created and the specified text is written to it successfully.")
 else 
  Call Log.Error("The file was not created.")
 End If
 
End Sub

DelphiScript

function CreatingAndWritingToTextFile;
begin
 if (aqFile.Create('C:\\MyFiles\\DemoFile.txt') = 0) then
 begin
  aqFile.WriteToTextFile('C:\\MyFiles\\DemoFile.txt', 'Hello!', aqFile.ctUTF8);
  Log.Message('The file is created and the specified text is written to it successfully.');
 end
  else 
 begin
  Log.Error('The file was not created.');
 end;
end;

C++Script, C#Script

function CreatingAndWritingToTextFile()
{
 if (aqFile["Create"]("C:\\MyFiles\\DemoFile.txt") == 0)
 {
  aqFile["WriteToTextFile"]("C:\\MyFiles\\DemoFile.txt", "Hello!", aqFile.ctUTF8);
  Log["Message"]("The file is created and the specified text is written to it successfully.");
 }
 else 
 {
  Log["Error"]("The file was not created.");
 }
}

See Also

Working With Files From Scripts
TestComplete Helper Objects
aqConvert Object
aqDateTime Object
aqEnvironment Object
aqFileSystem Object
aqObject Object
aqString Object
aqUtils Object