» Help

Code Snippets Database

Control Box
 
 

Requested snippet

This page displays the requested DeleteFileWithUndo snippet.

You can choose a category, perform a search or generate a Pascal unit containing the snippet by using the Control Box.

DeleteFileWithUndo
Deletes given file and sends it to recycle bin. Returns true if file deleted successfully.
function DeleteFileWithUndo(const FileName: string): Boolean;
var
  FOS: ShellAPI.TSHFileOpStruct;  // contains info about required file operation
begin
  // Set up structure that determines file operation
  FillChar(FOS, SizeOf(FOS), 0);
  with FOS do
  begin
    wFunc := ShellAPI.FO_DELETE;      // we're deleting
    pFrom := PChar(FileName + #0);    // this file (#0#0 terminated)
    fFlags := ShellAPI.FOF_ALLOWUNDO  // with facility to undo op
      or ShellAPI.FOF_NOCONFIRMATION  // and we don't want any dialogs
      or ShellAPI.FOF_SILENT;
  end;
  // Perform the operation
  Result := ShellAPI.SHFileOperation(FOS) = 0;
end;
Kind of Snippet: Routine
Required units: ShellAPI.
Required snippets: None.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED