Delete a file specified by its file name SysUtils unit
 function DeleteFile(const FileName string):Boolean;
The DeleteFile function deletes a file given by its file name FileName.
The file is looked for in the current directory.
If the file was deleted OK, then True is returned, otherwise False is returned.
This function is easier to use than the equivalent System unit Erase routine.
Warning : the Windows unit also has a DeleteFile function that takes a PChar argument.

To ensure that you use are using the intended one, type SysUtils.DeleteFile.
Related commands
AssignFileAssigns a file handle to a binary or text file
CloseFileCloses an open file
EraseErase a file
RenameRename a file
RenameFileRename a file or directory
 Download this web site as a Windows program.

Example code : Try to delete a file twice
  fileName : string;
  myFile   : TextFile;
  data     : string;

  // Try to open a text file for writing to
  fileName := 'Test.txt';
  AssignFile(myFile, fileName);

  // Write to the file
  Write(myFile, 'Hello World');

  // Close the file

  // Reopen the file in read mode

  // Display the file contents
  while not Eof(myFile) do
    ReadLn(myFile, data);

  // Close the file for the last time

  // Now delete the file
  if DeleteFile(fileName)
  then ShowMessage(fileName+' deleted OK')
  else ShowMessage(fileName+' not deleted');

  // Try to delete the file again
  if DeleteFile(fileName)
  then ShowMessage(fileName+' deleted OK again!')
  else ShowMessage(fileName+' not deleted, error = '+
Show full unit code
  Hello World
  Test.txt deleted OK
  Test.txt not deleted, error = 2
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page