(page requirements)

Delete files with the ability to undo or recycle

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;
  fos : TSHFileOpStruct;
  FillChar( fos, SizeOf( fos ), 0 );
  with fos do
    wFunc  := FO_DELETE;
    pFrom  := PChar( sFileName );
    fFlags := FOF_ALLOWUNDO
              or FOF_NOCONFIRMATION
              or FOF_SILENT;
  Result := ( 0 = ShFileOperation( fos ) );

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

Applicable Keywords : Delphi, Delphi 2.x, Functions, Windows NT, Windows NT 4.x, Windows, Win32, Windows 95
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor