function fileQuery(
const currDir:string;{目录名}
currExt:string;{扩展名}
const treeFlg,SortFlg:boolean;{是否搜索子目录,是否排序}
const fullFlg:boolean=true):string;{是否返回全路径}
const
strLine:string=#13#10
var
recFile :TSearchRec;
strTemp :string;
FlgTemp,intLoop :Integer;
begin{返回指定目录及其子目录下指定扩展名的文件列表}
result := '';
if(currDir = '') then exit;
if(currExt = '') then currExt := '*.*';
with TStringList.Create do
try
sorted := SortFlg;
Text := strTrue(pathQuery(currDir, treeFlg,SortFlg), currDir, treeFlg);
for intLoop:=0 to Count-1 do
begin
strTemp := '';
FlgTemp := FindFirst(strings[intLoop] +currExt, faAnyFile, RecFile);
while (FlgTemp=0) do
begin
if(RecFile.Attr and faDirectory =0) then
strTemp := strTemp +strTrue(strings[intLoop],'',fullFlg) +recFile.Name +strLine;
FlgTemp := FindNext(recFile);
end;
FindClose(recFile);
{排序}
with TStringList.Create do
try
sorted := SortFlg;
Text := strTemp;
result := result +Text;
finally
Free;
end;
end;
finally
Free;
end;
end;