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()
{
// Create a text file DemoFile.txt
if (aqFile.Create("C:\\MyFiles\\DemoFile.txt") == 0)
{
// If the file has been created successfully, write a string to it
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():
# Create a text file DemoFile.txt
if aqFile.Create("C:\\MyFiles\\DemoFile.txt") == 0:
# If the file has been created successfully, write a string to it
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
' Create a text file DemoFile.txt
If (aqFile.Create("C:\MyFiles\DemoFile.txt") = 0) Then
' If the file has been created successfully, write a string to it
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
// Create a text file DemoFile.txt
if (aqFile.Create('C:\\MyFiles\\DemoFile.txt') = 0) then
begin
// If the file has been created successfully, write a string to it
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()
{
// Create a text file DemoFile.txt
if (aqFile["Create"]("C:\\MyFiles\\DemoFile.txt") == 0)
{
// If the file has been created successfully, write a string to it
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