Function FindFile(const FileSpec: TFileName;attributes: integer): TStringList; Export;
var
Spec: String; //文件名
list: TStringList;
//------------------查询下级目录的子过程
procedure RFindFile(const Folder: TFileName);
var
SearchRec: TSearchRec;
begin
if FindFirst(Folder + Spec, Attributes, SearchRec)=0 then
begin
try
repeat
if (SearchRec.Attr and faDirectory = 0) or (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
list.Add(Folder + SearchRec.Name);
until FindNext(SearchRec) <> 0;
except
FindClose(SearchRec);
raise;
end;
FindClose(SearchRec);
end;
if FindFirst(Folder + '*', Attributes Or faDirectory, SearchRec) = 0 then
begin
try
repeat
if ((SearchRec.Attr and faDirectory) <> 0) and
(SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
RFindFile(Folder + SearchRec.Name + '\');
until FindNext(SearchRec) <> 0;
except
FindClose(SearchRec);
raise;
end;
FindClose(SearchRec);
end;
end;
//------------------
begin
List := TStringList.Create;//创建字符传列表
try
spec := ExtractFileName(filespec);//返回指定文件名
RFindFile(ExtractFilePath(filespec));//返回指定路径
Result := list;//函数返回值是List;
Except
List.Free;
raise;
end;
end;
FindFile(文件夹路径+'\*.txt',0) 返回一个包含所有TXT文件路径的TStringList
|