nbsp; if dir[length(dir)]<>'''' then
result:=dir+''''
else
result:=dir;
end;
procedure TForm1.findfiles(apath: string);
{通过递归调用,可以在当前目录和子目录下查找指定格式的文件}
var
fsearchrec,dsearchrec:tsearchrec;
findresult:integer;
function isdirnotation(adirname:string):boolean;
begin
result:=(adirname=''.'') or (adirname=''..'');
end;
begin
apath:=getdirectoryname(apath); //获取一个有效的目录名称
{查找一个匹配的文件}
findresult:=findfirst(apath+ffilename,faanyfile+fahidden+fasysfile+fareadonly,fsearchrec);
try
{继续查找匹配的文件}
while findresult=0 do
begin
Listbox1.Items.Add(lowercase(apath+fsearchrec.Name));
t:=t+1;
label1.Caption:=inttostr(t);
findresult:=findnext(fsearchrec);
end;
{在当前目录的子目录中进行查找}
findresult:=findfirst(apath+''*.*'',fadirectory,dsearchrec);
while findresult=0 do
begin
if ((dsearchrec.Attr and fadirectory)=fadirectory) and not
isdirnotation(dsearchrec.Name) then
findfiles(apath+dsearchrec.Name);//在此处是递归调用
findresult:=findnext(dsearchrec);
end;
finally
findclose(fsearchrec);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
{调用FindFiles()函数