Back


Lennie's Weekly Tip : Deleting Files in Delphi
14 June 2000 Ref. 25

To delete files from your Delphi application(s) you can now use the DeleteFile function, that's equivalent to the DeleteFile WinAPI function, declared inside the SysUtils unit.

Declaration
-----------

function DeleteFile(const FileName: string): Boolean;

Description
------------

The DeleteFile function erases the file named by FileName from the disk.
If the file cannot be deleted or does not exist, the function returns False.

Example
-------
if not (DeleteFile('names.tmp')) then
  Messagedlg('ERROR: Can''t delete names.tmp file !', mterror, [mbok], 0);
 

In this example the DeleteFile function will delete the file "names.tmp", if it fails a error will be displayed.
 

WARNING: The DeleteFile function will permanently delete the file and doesn't delete it too the Recycle Bin.
 

For more information read Delphi's on-line help.


Back