unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, <br> Controls, Forms, Dialogs, StdCtrls, Buttons,<br> ShellAPI;//要引用ShellApI<br><br>type<br> TForm1 = class(TForm)<br> BitBtn1: TBitBtn;<br> procedure BitBtn1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br> T:TSHfileOpStruct;//要引用ShellApI<br><br> P:String;<br>begin<br> P:='C:/My Documents/test/abc';//要写完整路径。<br> with T do<br> begin<br> Wnd := 0;<br> wFunc := FO_DELETE;<br> pFrom := pchar(p);<br> pTo := nil;<br> fFlags := FOF_ALLOWUNDO;<br> end;<br> SHFileOperation(T);<br>end;<br><br>end.<br><br>不仅可以删除非空目录,还能在回收站恢复。<br>