16,748
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.GetFileToListBox(srcPath,sExt: string);
var FileRec: TSearchrec;
currPath : string;
begin
if srcPath[Length(srcPath)] <> '\' then srcPath := srcPath + '\';
currPath := srcPath + '*.*';
if FindFirst(currPath, faAnyFile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) and
(FileRec.Name <> '.') and
(FileRec.Name <> '..') then
begin
GetFileToListBox(srcPath+ FileRec.Name,sExt);
end
else begin
if ExtractFileExt(FileRec.Name)=sExt then
ListBox1.Items.Add(FileRec.Name);
end;
until FindNext(FileRec) <> 0;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
GetFileToListBox('L:\','.jpg');
end;
上机运行通过。