News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Delete files with the ability to undo or recycle

Started by charleychacko, October 15, 2006, 12:13:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

charleychacko

Windows will not let the user or your program undo file delete operations that your perform using low-level functions such as DeleteFile() from your program. Following function, however, will delete a file with the ability to undo (recycle) by sending the file to the "Recycle Bin."
uses ShellAPI;

function DeleteFileWithUndo(
  sFileName : string )
    : boolean;
var
  fos : TSHFileOpStruct;
begin
  FillChar( fos, SizeOf( fos ), 0 );
  with fos do
  begin
    wFunc  := FO_DELETE;
    pFrom  := PChar( sFileName );
    fFlags := FOF_ALLOWUNDO
              or FOF_NOCONFIRMATION
              or FOF_SILENT;
  end;
  Result := ( 0 = ShFileOperation( fos ) );
end;


To delete a file, simply pass the file name to DeleteFileWithUndo() and it will return True if the operation was successful.