Solved

Delete files to the Recycle Bin?

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

12 Experts available now in Live!

Get 1:1 Help Now