以下这段代码是浏览硬盘上所有文件夹,并把文件夹的内容作为节点加入到TreeView中,如果找到bmp文件,则加入到下一级中.请就这段代码指正,只将含有bmp的文件夹作为节点加入到TreeView中
另 请问CJ,WinApi 中现成的例程是什么?
procedure TApplyForm.SearchNewFile( pathfile : string;
ParentNode: TTreeNode );
var
SearchRec : TSearchRec;
IFound : integer;
newnode : TTreeNode;
FileNode : TTreeNode;
ExtName : string;
begin
IFound := FindFirst( pathfile + '/*.*', faAnyFile, SearchRec );
While IFound = 0do
begin
StatusBar1.Panels[0].Text := '目录检索中';
if ( SearchRec.Attr = faDirectory ) and ( SearchRec.Name <> '.' )
and ( SearchRec.Name <> '..' ) then
begin
newnode := TreeView1.Items.AddChild( ParentNode, SearchRec.Name );
newnode.ImageIndex := 3;
newnode.SelectedIndex := 3;
//SearchNewFile( pathFile + '/' + SearchRec.Name, newnode );
SearchNewFile( pathFile + '/' + SearchRec.Name, newnode );
end
else
begin
ExtName := ExtractFileExt( SearchRec.Name );
if ExtName = '.bmp' then
begin
FileNode := TreeView1.Items.AddChild( ParentNode, ExtractFileName( SearchRec.Name) );
FileNode.ImageIndex := 4;
FileNode.SelectedIndex := 4;
end;
end;
IFound := FindNext( SearchRec );
end;
StatusBar1.Panels[0].Text := '就绪';
FindClose( SearchRec );
end;