一个函数,结果用参数foundresult返回:
function SearchFile(mainpath:string;filename:string; var foundresult:TStrings):Boolean;
var
i:integer;
Found:Boolean;
subdir1:TStrings;
searchRec:TsearchRec;
begin
if right(mainpath,1)<>'/' then mainpath:=mainpath+'/';
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 (FindFirst(mainpath+'*.*', faAnyFile-faDirectory, SearchRec)=0) then
begin
foundresult.Add(mainpath+SearchRec.Name);
while (FindNext(SearchRec) = 0) do
begin
foundresult.Add(mainpath+SearchRec.Name);
end;
end;
FindClose(SearchRec);
for i:=0 to subdir1.Count-1 do
found:=Searchfile(mainpath+subdir1.Strings+
'/',Filename,foundresult)or found;
subdir1.Free;
end;
result:=found;
end;