Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete files to the Recycle Bin?

Posted on 1998-09-20
1
Medium Priority
?
390 Views
Last Modified: 2010-04-06
how do I delete files to the recycle bin? Does delphi provide a way or do I have to get the recycle bin dir from windows and then just move files there?
0
Comment
Question by:ripcord
1 Comment
 
LVL 1

Accepted Solution

by:
Edo082297 earned 200 total points
ID: 1340375
program del;

uses ShellApi;

//function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall;
Var
  T:TSHFileOpStruct;    
  P:String;
begin  
  P:='C:\Windows\System\EL_CONTROL.CPL';
  With T do  
  Begin    
    Wnd := 0;    
    wFunc := FO_DELETE;    
    pFrom:=Pchar(P);
    fFlags:=FOF_ALLOWUNDO  
  end;  
  SHFileOperation(T);

End.

1) Give the complete path to the file

2) MS has a documentation correction about the pFrom member. It says that for multiple files, each filename is seperated by a NULL (#0) character, and the whole thing is terminated by double NULLs. You need the double NULL whether or not you are passing multiple filenames. Sometimes it will work correctly without them, but often not. That's because sometimes you get lucky and the memory following the end of your string has a NULL there.

An example of how to do this would be:

var
  FileList: string;
  FOS: TShFileOpStruct;
begin
  FileList := 'c:\delete.me'#0'c:\windows\temp.$$$'#0#0;
  { if you were using filenames in string variables: }
  FileList := Filename1 + #0 + Filename2 + #0#0;

  FOS.pFrom := PChar(FileList);

  // blah blah blah
end;


Thanks to Brad Stowers (ZifNab ?) and UDDF for this information, whose help file may be obtained from

http://www.gnomehome.demon.nl/uddf/uddf.arj 


Regards,
Edo


0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question