procedure DelFile(Directory: string;var List:TstringList);
var
Search, Src: TSearchRec;
RootDirectory: string;
FCount: Integer;
begin
Application.ProcessMessages;
//查找文件
RootDirectory := Directory;
if RootDirectory[Length(RootDirectory)] <> '/' then RootDirectory := RootDirectory + '/';
//先查找文件
if FindFirst(RootDirectory + '*.mdb', faAnyFile, Src) = 0 then
repeat
List.add(RootDirectory + Search.Name);
until FindNext(Src) <> 0;
//再查目录
if FindFirst(RootDirectory + '*.*', faDirectory, Search) = 0 then
repeat
if (Search.Name <> '.') and (Search.Name <> '..') then
if (Search.Attr and fadirectory) = fadirectory then
begin
//form1.lbl1.caption := '正在修改...' + RootDirectory + Search.Name;
DelFile(RootDirectory + Search.Name);
end;
until FindNext(Search) <> 0;
FindClose(Search);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
list;Tstringlist;
begin
list:=Tstringlist.create;
DelFile('你的备份目录',List);
if list.count>=3 then
begin
for i:=0 to list.count-4 do
delfile(list);
end;
list.free;
end;
现写的,没在DELPHI中测试,你可以试一下,大致思路是这样的.