aqFile.Delete Method

Applies to TestComplete 15.46, last modified on January 09, 2023

Description

Use the aqFile.Delete method to remove one or more files from the disk.

Declaration

aqFile.Delete(PathToFile)

PathToFile [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile

The fully-qualified path (including the name) of the file to be deleted. To delete several files, use wildcards (* and ?) to specify the mask. Note, that wildcards are only allowed in the file names, not in paths.

Result Value

True if the deletion succeeds, and False otherwise.

Note: If the specified file was not found, the method returns True.

Remarks

If the method fails to delete the file, TestComplete will post an information message to the test log explaining the cause of the failure.

Example

The code below creates a new text file, writes some temporary data to it and then deletes this file at the end of the test.

JavaScript, JScript

function DeletingFile()
{
 var sPath = "C:\\Temp\\TempFile.txt";
 
 // Creates a file
 aqFile.Create(sPath);
 
 // Writes some data to the file
 aqFile.WriteToTextFile(sPath, "The temporary data.", aqFile.ctANSI);
 
 // Performs some actions over the file's content
 
 // Deletes the file
 aqFile.Delete(sPath);
}

Python

def DeletingFile():
  sPath = "C:\\Temp\\TempFile.txt"
  # Creates a file
  aqFile.Create(sPath)
  # Writes some data to the file
  aqFile.WriteToTextFile(sPath, "The temporary data.", aqFile.ctANSI)
  # Performs some actions over the file's content
  # Deletes the file
  aqFile.Delete(sPath)

VBScript

Sub DeletingFile
 sPath = "C:\Temp\TempFile.txt"
 
 ' Creates a file
 Call aqFile.Create(sPath)
 
 ' Writes some data to the file
 Call aqFile.WriteToTextFile(sPath, "The temporary data.", aqFile.ctANSI)
 
 ' Performs some actions over the file's content
 
 ' Deletes the file
 Call aqFile.Delete(sPath)
End Sub

DelphiScript

function DeletingFile;
var sPath;
begin
 sPath := 'C:\Temp\TempFile.txt';
 
 // Creates a file
 aqFile.Create(sPath);
 
 // Writes some data to the file
 aqFile.WriteToTextFile(sPath, 'The temporary data.', aqFile.ctANSI);
 
 // Performs some actions over the file's content
 
 // Deletes the file
 aqFile.Delete(sPath);
end;

C++Script, C#Script

function DeletingFile()
{
 var sPath = "C:\Temp\TempFile.txt";
 
 // Creates a file
 aqFile["Create"](sPath);
 
 // Writes some data to the file
 aqFile["WriteToTextFile"]( sPath, "The temporary data.", aqFile.ctANSI );
 
 // Performs some actions over the file's content
 
 // Deletes the file
 aqFile["Delete"](sPath);
}

The code below deletes all text files from the C:\Temp folder.

JavaScript, JScript

function DeletingFiles()
{
 var sPath = "C:\\Temp\\*.txt";

 // Deletes the files
 aqFile.Delete(sPath);
}

Python

def DeletingFiles():
  sPath = "C:\\Temp\\*.txt"
  # Deletes the files
  aqFile.Delete(sPath)

VBScript

Sub DeletingFiles
 sPath = "C:\Temp\*.txt"

 ' Deletes the files
 Call aqFile.Delete(sPath)
End Sub

DelphiScript

function DeletingFiles;
var sPath;
begin
 sPath := 'C:\Temp\*.txt';

 // Deletes the files
 aqFile.Delete(sPath);
end;

C++Script, C#Script

function DeletingFiles()
{
 var sPath = "C:\Temp\*.txt";

 // Deletes the files
 aqFile["Delete"](sPath);
}

See Also

Working With Files From Scripts
Create Method
Exists Method
Move Method
Rename Method
Copy Method

Highlight search results