1. Home
  2. Computing & Technology
  3. Delphi Programming

Delete files with the ability to UNDO

By Zarko Gajic, About.com Guide

Here's a Delphi procedure that can delete a file with the ability to undo by sending the file to the "Recycle Bin."

Function FileDeleteRB will return True if the operation was successful.

~~~~~~~~~~~~~~~~~~~~~~~~~
uses ShellAPI;

function FileDeleteRB(
   AFileName:string): boolean;
var Struct: TSHFileOpStruct;
    pFromc: array[0..255] of char;
    Resultval: integer;
begin
   if not FileExists(AFileName) then begin
      Result := False;
      exit;
   end
   else begin
      fillchar(pfromc,sizeof(pfromc),0) ;
      StrPcopy(pfromc,expandfilename(AFileName)+#0#0) ;
      Struct.wnd := 0;
      Struct.wFunc := FO_DELETE;
      Struct.pFrom := pFromC;
      Struct.pTo := nil;
      Struct.fFlags:= FOF_ALLOWUNDO or FOF_NOCONFIRMATION
         or FOF_SILENT;
      Struct.fAnyOperationsAborted := false;
      Struct.hNameMappings := nil;
      Resultval := ShFileOperation(Struct) ;
      Result := (Resultval = 0) ;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Add documents to the Windows Start-Documents Menu
« Execute the Windows Explorer Find File Dialog Box

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. Delete files with the ability to UNDO

©2009 About.com, a part of The New York Times Company.

All rights reserved.