Mega Code Archive

 
Categories / Delphi / Files
 

Send a file to windows recycle bin

Title: Send a file to windows recycle bin Question: How can I send a file to windows recycle bin? Answer: Don't forget to add ShellAPI in your uses-group. This is the function that does all the work: function RecycleFile(sFileName: string): Boolean; var FOS: TSHFileOpStruct; begin FillChar(FOS, SizeOf(FOS), 0); with FOS do begin wFunc := FO_DELETE; { Functions as FO_COPY also works. pFrom := PChar(sFileName + #0); pTo := { Only for FO_COPY } fFlags := FOF_ALLOWUNDO; { Since we wan't to send the file the file to recycle bin } end; // Send the file Result := (SHFileOperation(FOS) = 0); end; Call the function by using this line: RecycleFile('E:\Test.exe');