procedure TForm2.dispdir4(spath:string;node:TTreeNode); var cnode:TTreeNode; ffd:WIN32_FIND_DATA ; hFind:THandle; Dest:string; hstr:string; begin if copy(spath,length(spath),1)<>'\' then spath:=spath+'\'; Dest:=Spath+'*.*';
hFind:=FindFirstFile(PChar(Dest),ffd); if hFind>0 then begin//1 hstr:=ffd.cFileName; if ffd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then begin//2 if (ffd.cFileName[0]<>'.') then begin//3 cnode:=tv1.Items.AddChild(Node,hstr ); cnode.ImageIndex :=1; cnode.SelectedIndex :=cnode.ImageIndex; dispdir4( spath+hstr ,cnode); end;//3 end//2 else begin//22 cnode:=tv1.Items.AddChild(Node,hstr ); cnode.ImageIndex :=0; cnode.SelectedIndex :=cnode.ImageIndex; end;//22 end;//1 while FindNextFile(hFind,ffd)=true do begin//4 hstr:=ffd.cFileName; if ffd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then begin//2 if (ffd.cFileName[0]<>'.') then begin//3 cnode:=tv1.Items.AddChild(Node,hstr ); cnode.ImageIndex :=1; cnode.SelectedIndex :=cnode.ImageIndex; dispdir4( spath+hstr,cnode); end;//3 end//2 else begin//22 cnode:=tv1.Items.AddChild(Node,hstr ); cnode.ImageIndex :=0; cnode.SelectedIndex :=cnode.ImageIndex; end;//22 end;//4
end; 我用这段读入C:\Documents and Settings\Administrator到