这个不错,网上的
下面是主要方法
function TForm1.IsValidDir(SearchRec: TSearchRec): Boolean;
begin
if (SearchRec.Attr=16) and (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
result:=true
else
result:=false;
end;
function TForm1.SearchFile(mainpath, filename: string;
var foundresult: TStrings): Boolean;
var
i:Integer;
Found:Boolean;
subdir1:TStrings;
searchRec:TSearchRec;
begin
Found:=false;
if trim(filename)<>'' then
begin
subdir1:=TStringList.Create;
if (FindFirst(mainpath+'*.*',faDirectory,searchRec)=0) then
begin
if IsValidDir(SearchRec) then
subdir1.Add(SearchRec.Name);
while (FindNext(SearchRec)=0 ) do
begin
if IsValidDir(SearchRec) then
subdir1.Add(SearchRec.Name);
end;
end;
FindClose(SearchRec);
if FileExists(mainpath+filename) then
begin
Found:=true;
foundresult.Add(mainpath+filename);
end;
for i:=0 to subdir1.Count-1 do
found:=SearchFile(mainpath+subdir1.Strings+'/',FileName,foundresult);
subdir1.Free;
end;
result:=found;
end;