If you want to delete a file and have the ability to recycle it you should better forget about low-level functions such as DeleteFile(). You need to use the Shell API functions in order to use the recycle bin. This is because deleting files with the use of the recycle bin is not just moving it there =)
Here is the code you should use:
uses ShellAPI;
...
function RecycleFile(sFileName: string): Boolean;
var
FOS: TSHFileOpStruct;
begin
FillChar(FOS, SizeOf(FOS), 0);
with FOS do begin
wFunc := FO_DELETE;
pFrom := PChar(sFileName);
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT;
end;
Result := (SHFileOperation(FOS) = 0);
end;
Tags: api, clx, delete, Delphi, documents, files, mdf, object pascal, recycle, shell, tip, trick, vcl, windows
Merlin’s Delphi Forge
Leave a comment