Solved

Delete files to the Recycle Bin?

Posted on 1998-09-20
1
374 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 88
Correct Component for Shopping Cart. 2 96
Magic Software info 18 125
SUM 2 INTEGER ARRAYS INTO 1 10 93
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now