Author: Jonas Bilinkevicius How to send files to the recycle bin Answer: Solve 1: 1 unit Recycle; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, ShellAPI; 7 8 function RecycleFile(FileToRecycle: TFilename): boolean; 9 function RecycleFileEx(FileToRecycle: TFilename; Confirm: boolean): boolean; 10 11 implementation 12 13 function RecycleFile(FileToRecycle: TFilename): boolean; 14 begin 15 Result := RecycleFileEx(FileToRecycle, True); 16 end; 17 18 function RecycleFileEx(FileToRecycle: TFilename; Confirm: boolean): boolean; 19 var 20 Struct: TSHFileOpStruct; 21 tmp: string; 22 Resultval: integer; 23 begin 24 tmp := FileToRecycle + #0#0; 25 Struct.wnd := 0; 26 Struct.wFunc := FO_DELETE; 27 Struct.pFrom := PChar(tmp); 28 Struct.pTo := nil; 29 Struct.fFlags := FOF_ALLOWUNDO; 30 if not Confirm then 31 Struct.fFlags := Struct.fFlags or FOF_NOCONFIRMATION; 32 Struct.fAnyOperationsAborted := false; 33 Struct.hNameMappings := nil; 34 try 35 Resultval := ShFileOperation(Struct); 36 except 37 on e: Exception do 38 begin 39 e.message := 'Tried to recycle file:' + FileToRecycle + #13#10 + e.message; 40 raise; 41 end; 42 end; 43 Result := (Resultval = 0); 44 end; 45 46 end. Solve 2: 47 uses ShellApi; 48 49 function DeleteFilesToRecycleBin(const APath: string): Boolean; 50 var 51 AStruct: TShFileOpStruct; 52 begin 53 if Length(APath) = 0 then 54 Exit; 55 AStruct.Wnd := 0; 56 AStruct.wFunc := FO_DELETE; 57 AStruct.pFrom := PChar(APath); 58 AStruct.fFlags := FOF_ALLOWUNDO; 59 Result := ShFileOperation(AStruct) <> 0; 60 end; Solve 3: 61 62 function RecycleFile(FileToRecycle: string): boolean; 63 var 64 Struct: TSHFileOpStruct; 65 pFromc: PChar; 66 Resultval: integer; 67 begin 68 if not FileExists(FileToRecycle) then 69 begin 70 RecycleFile := False; 71 exit; 72 end 73 else 74 begin 75 pfromc := PChar(ExpandFileName(FileToRecycle) + #0#0); 76 Struct.wnd := 0; 77 Struct.wFunc := FO_DELETE; 78 Struct.pFrom := pFromC; 79 Struct.pTo := nil; 80 Struct.fFlags := FOF_ALLOWUNDO; 81 Struct.fAnyOperationsAborted := false; 82 Struct.hNameMappings := nil; 83 Resultval := ShFileOperation(Struct); 84 RecycleFile := (Resultval = 0); 85 end; 86 end;