楼主把分给我吧:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(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 do_something(startdir,filename,status:string);<br>begin<br> if status='delete' then<br> begin<br> deletefile(startdir+filename);<br> end;<br>end;<br><br>procedure FindFiles(StartDir,searchfilename: string;searchsubdir:boolean;status:string);<br>var<br> SR: TSearchRec;<br> IsFound: Boolean;<br>begin<br> IsFound :=FindFirst(StartDir+searchfilename, faAnyFile-faDirectory, SR) = 0;<br> while IsFound do begin<br> do_something(startdir,sr.name,status);<br> IsFound := FindNext(SR) = 0;<br> end;<br> FindClose(SR);<br> if searchsubdir=false then exit;<br> IsFound := FindFirst(StartDir+'*.*', faAnyFile, SR) = 0;<br> while IsFound do begin<br> if ((SR.Attr and faDirectory) <> 0) and(SR.Name[1] <> '.') then findfiles(startdir+sr.Name+'/',searchfilename,true,status);<br> IsFound := FindNext(SR) = 0;<br> end;<br> FindClose(SR);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> path:string;<br>begin<br> path:='d:/'';<br> findfiles(path,'*.log',true,'delete');<br>end;<br><br>end.<br><br>这个程序是删除D:/下所有文件夹下的(包含所有的子目录)中的LOG文件,如果你不想包含子目录,则把findfiles(path,'*.log',true,'delete')这句的true改成false即可。