Delete Method

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

Use the Delete method to delete the file to which the given aqFileInfoObj object corresponds.

Declaration

aqFileInfoObj.Delete()

aqFileInfoObj An expression, variable or parameter that specifies a reference to an aqFileInfo object
Result Boolean

Applies To

The method is applied to the following object:

Result Value

True if the file was removed successfully, and False if it was not.

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 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);
 
 var FileInf = aqFileSystem.GetFileInfo(sPath);

 // Writes some data to the file
 FileInf.WriteToTextFile("The temporary data.", aqFile.ctANSI);
 
 // Performs some actions over the file's content
 
 // Deletes the file
 FileInf.Delete();
}

Python

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

VBScript

Sub DeletingFile
 sPath = "C:\Temp\TempFile.txt"
 
 ' Creates a file
 Call aqFile.Create(sPath)
 
 Set FileInf = aqFileSystem.GetFileInfo(sPath)

 ' Writes some data to the file
 Call FileInf.WriteToTextFile("The temporary data.", aqFile.ctANSI)
 
 ' Performs some actions over the file's content
 
 ' Deletes the file
 Call FileInf.Delete()
End Sub

DelphiScript

function DeletingFile;
var sPath, FileInf;
begin
 sPath := 'C:\Temp\TempFile.txt';
 
 // Creates a file
 aqFile.Create(sPath);
 
 FileInf := aqFileSystem.GetFileInfo(sPath);

 // Writes some data to the file
 FileInf.WriteToTextFile('The temporary data.', aqFile.ctANSI);
 
 // Performs some actions over the file's content
 
 // Deletes the file
 FileInf.Delete();
end;

C++Script, C#Script

function DeletingFile()
{
 var sPath = "C:\Temp\TempFile.txt";
 
 // Creates a file
 aqFile["Create"](sPath);
 
 var FileInf = aqFileSystem.GetFileInfo(sPath);

 // Writes some data to the file
 FileInf["WriteToTextFile"]( "The temporary data.", aqFile.ctANSI );
 
 // Performs some actions over the file's content
 
 // Deletes the file
 FileInf["Delete"]();
}

See Also

Working With Files From Scripts
Exists Property
Move Method
Copy Method

Highlight search results