var
F: TSearchRec;
Res: Integer;
begin
Res := FindFirst('F:\1\*.txt', faAnyFile, f);
try
while Res = 0 do
begin
Memo1.Lines.Add(f.Name);
Res := FindNext(F);
end;
finally
FindClose(F);
end;
end;
用FindFirst、FindNext、FindClose来查找:
var sr : TSearchRec;
found : integer;
Path, Ext : string;
begin
path := 'f:\1\';
Ext := '.txt';
found := FindFirst(path+'*.*',faAnyFile,sr);
while (found=0) do
begin
if sr.Name[1]<>'.' then
begin
if ((sr.Attr and faDirectory)=0)and(ExtractFileExt(sr.Name)=Ext) then
begin
//找到,读取文件sr.Name
end;
end;
found:=FindNext(sr);
end;
FindClose(sr);
end;