从hubdog上粘过来的<br><br>代码如下:<br><br>1. 从搜索记录中判断是否是子目录。<br><br> <br><br>function IsValidDir(SearchRec:TSearchRec):Boolean;<br><br>begin<br><br><br>if (SearchRec.Attr=16) and<br><br>(SearchRec.Name<>'.') and<br><br>(SearchRec.Name<>'..') then<br><br>Result:=True<br><br>else<br><br>Result:=False;<br><br>end;<br><br>2. 这是查询主体函数。<br><br>参数介绍:<br><br>Mainpath: 指定的查询目录。<br><br>Filename: 欲查询的文件。<br><br>Foundresult: 返回的含完整路径的匹配文件(可能有多个)。<br><br>如果有匹配文件,函数返回True,否则,返回False;<br><br> <br><br>function SearchFile(mainpath:string;filename:string;<br><br>var foundresult:TStrings):Boolean;<br><br>var<br><br>i:integer;<br><br>Found:Boolean;<br><br>subdir1:TStrings;<br><br>searchRec:TsearchRec;<br><br>begin<br><br>found:=false;<br><br>if Trim(filename)<>'' then<br><br>begin<br><br>subdir1:=TStringList.Create;//字符串列表必须动态生成<br><br>//找出所有下级子目录。<br><br>if (FindFirst(mainpath+'*.*', faDirectory, SearchRec)=0) then<br><br>begin<br><br>if IsValidDir(SearchRec) then<br><br>subdir1.Add(SearchRec.Name);<br><br>while (FindNext(SearchRec) = 0) do<br><br>begin<br><br>if IsValidDir(SearchRec) then<br><br>subdir1.Add(SearchRec.Name);<br><br>end;<br><br>end;<br><br>FindClose(SearchRec);<br><br>//查找当前目录。<br><br>if FileExists(mainpath+filename) then<br><br>begin<br><br>found:=true;<br><br>foundresult.Add(mainpath+filename);<br><br>end;<br><br>//这是递归部分,查找各子目录。<br><br>for i:=0 to subdir1.Count-1 do<br><br>found:=Searchfile(mainpath+subdir1.Strings+<br><br>'/',Filename,foundresult)or found;<br><br>//资源释放并返回结果。<br><br>subdir1.Free;<br><br>end;<br><br>result:=found;<br><br>end;<br><br>若要大小等属性 可以从TsearchRec中取得 <br><br><br>