Mega Code Archive

 
Categories / Delphi / Files
 

Sending a file to Windows Recycle Bin (for beginners)

Title: Sending a file to Windows Recycle Bin (for beginners) Question: If you want to send a file to Windows Recycle Bin with code, try this... Answer: // send the specified file to Windows Recycle Bin function RecycleBinDelete(strFileName: string): boolean; var recFileOpStruct: TSHFileOpStruct; begin // clear the structure FillChar(recFileOpStruct, SizeOf(TSHFileOpStruct), 0); with recFileOpStruct do begin wFunc := FO_DELETE; pFrom := PChar(strFileName); fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT; end; // set the return with sucess of the operation result := (0 = ShFileOperation(recFileOpStruct)); end;