Mega Code Archive

 
Categories / Delphi / Examples
 

Send files to the recycle bin

If you don't like to use DeleteFile, because it removes files from the hard disc completely, you might want to use the following function which removes files, but optionally allows an undo: procedure RecycleFile(s : string); var SHFileOpStruct : TSHFileOpStruct; begin with SHFileOpStruct do begin Wnd := 0; wFunc := FO_DELETE; // we want to delete a file... pFrom := PChar(s+#0+#0); //... this file ... pTo := nil; fFlags := FOF_ALLOWUNDO; //... able to "Undo" (recycle) hNameMappings := nil; lpszProgressTitle := nil; end; SHFileOperation(SHFileOpStruct); // to the Recycle Bin end;