Beranda > Delphi > Delete files with the ability to undo or recycle

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;
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.

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: