DelphiFAQ Home Search:

Send files to the recycle bin

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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;

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.