查找文件
1 procedure TForm2.FindFile(APath: string; Filter: string; Rev: TStrings;
2 SubDir: Boolean);
3 var
4 R: Integer;
5 F: TSearchRec;
6 begin
7 if APath[Length(APath)] <> '\' then
8 APath := APath + '\';
9 R := FindFirst(APath + '*.*', faAnyFile, F);
10 while R = 0 do
11 begin
12 if (F.Attr and faDirectory = faDirectory) and SubDir then
13 begin
14 if (F.Name <> '.') and (F.Name <> '..') then
15 begin
16 FindFile(APath + F.Name, Filter, Rev);
17 end;
18 end
19 else
20 begin
21 if (Filter = '*.*') or
22 (LowerCase(ExtractFileExt(Filter)) = LowerCase(ExtractFileExt(F.Name)))
23 then
24 Rev.Add(F.Name);
25 end;
26 R := FindNext(F);
27 end;
28 FindClose(F);
29 end;