下面是一个进行目录搜索的例程,经过修改你可以搜索需要的文件类型
procedure searchpath(path:string);
var
SearchRec : TSearchRec;
ext : string; //后缀
begin
//在路径后面加上'/'
if path[Length(path)] <> '/' then path := path + '/';
if FindFirst(path + '*.*', faAnyFile, SearchRec) <> 0 then Exit;
//判断是否为目录,是目录则循环
if (SearchRec.Attr and faDirectory) <> 0 then
begin
if (SearchRec.name<>'.') and (SearchRec.Name<>'..') then
SearchPath(path+searchrec.name);
end
else
begin
{ 此处加上你自已的判断文件后缀的代码
ext := LowerCase(ExtractFileExt( SearchRec.Name ));
if (ext='.bmp') or (ext='.jpg') then
begin
...
end;}
end;
while FindNext(SearchRec)=0 do
begin
if (SearchRec.Attr and faDirectory) <> 0 then
begin
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
SearchPath(path+SearchRec.Name);
end
else
begin
{ 此处加上你自已的判断文件后缀的代码
ext := LowerCase(ExtractFileExt( SearchRec.Name ));
if (ext='.bmp') or (ext='.jpg') then
begin
...
end;}
end;
end;
FindClose(SearchRec);
end;