Внешний вид сайта:

Удаление файлов с Undo

Как можно удалить файл с отменой удаления (перемещение в Корзину Windows)?

Пример кода:

{ Thanks to Poul Dige for this comment: 
  ALWAYS make sure, that FileName ends with two chr(0), i.e. 
  FileName := FileName+#0+#0; 

  If you want to process more than one file, the file names 
  should be separated by a single #0, e.g. 
  FileName := File1+#0+File2+#0.....+FileN+#0+#0; } 

uses 
  ShellApi; 

function DeleteFileWithUndo(FileName: string): boolean; 
var 
  SHFileOpStruct: TSHFileOpStruct; 
begin 
  FillChar(SHFileOpStruct, SizeOf(SHFileOpStruct), 0); 

  with SHFileOpStruct do 
  begin 
    { specifies the operation } 
    wFunc  := FO_DELETE; 

    { specifies the filename to operate } 
    pFrom  := PChar(FileName); 

    { flags for controlling the operation } 
    { Preserves undo information, Responds with yes to all 
      for any dialog box that is displayed, doesn't display a 
      progress dialog } 
    fFlags := FOF_ALLOWUNDO 
              or FOF_NOCONFIRMATION 
              or FOF_SILENT; 
  end; 

  { returns true if successful, otherwise false } 
  result := (0 = ShFileOperation(SHFileOpStruct)); 
end;

Комментарии

Нет комментариев. Ваш будет первым!