aqFile.Create Method

Applies to TestComplete 15.68, last modified on October 16, 2024

Description

Use the Create method to create a new empty file at the specified location.

Declaration

aqFile.Create(PathToFile)

PathToFile [in]    Required    String    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile

Specifies the fully-qualified path (including the name) to the file to be created.

Note: The folder where you want to create a file must exist.

Result Value

If the creation succeeds, the method returns zero; otherwise, it returns the error code. To get a description that corresponds to the given error code, you can use the aqUtils.SysErrorMessage method. A complete list of error codes is provided in the System Error Codes article in the MSDN library.

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
Delete Method
Exists Method
Move Method
Rename Method
Copy Method
CreateFolder Method
SysErrorMessage Method

Highlight search results