V
visual_cjiajia
Unregistered / Unconfirmed
GUEST, unregistred user!
FILE_ATTRIBUTE_DIRECTORY解决了<br><br>procedure TForm2.dispdir4(spath:string;node:TTreeNode);<br>var<br> cnode:TTreeNode;<br> ffd:WIN32_FIND_DATA ;<br> hFind:THandle;<br> Dest:string;<br> hstr:string;<br> hwstr:string;<br>begin<br>if copy(spath,length(spath),1)<>'/' then<br> spath:=spath+'/';<br>Dest:=Spath+'*.*';<br><br> hFind:=FindFirstFile(PChar(Dest),ffd);<br> if hFind>0 then<br> begin//1<br> hstr:=ffd.cFileName;<br> hwstr:=Spath+hstr;<br> if (ffd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)>0 then<br> begin//2<br> if (ffd.cFileName[0]<>'.')and (ffd.cFileName[0]<>'..') then<br> begin//3<br> cnode:=tv1.Items.AddChild(Node,hstr );<br> cnode.ImageIndex :=1;<br> cnode.SelectedIndex :=cnode.ImageIndex;<br> dispdir4( spath+hstr ,cnode);<br> end;//3<br> end//2<br> else<br> begin//22<br> if extractfileext(hwstr)='.lnk' then<br> begin//1<br> cnode:=tv1.Items.AddChild(Node,hstr );<br> cnode.ImageIndex :=0;<br> cnode.SelectedIndex :=cnode.ImageIndex;<br> end;//1<br> end;//22<br> end;//1<br> while FindNextFile(hFind,ffd)=true do<br> begin//4<br> hstr:=ffd.cFileName;<br> hwstr:=Spath+hstr;<br> if (ffd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)>0 then<br> begin//2<br> if (ffd.cFileName[0]<>'.')and (ffd.cFileName[0]<>'..') then<br> begin//3<br> cnode:=tv1.Items.AddChild(Node,hstr );<br> cnode.ImageIndex :=1;<br> cnode.SelectedIndex :=cnode.ImageIndex;<br> dispdir4( spath+hstr,cnode);<br> end;//3<br> end//2<br> else<br> begin//22<br> if extractfileext(hwstr)='.lnk' then<br> begin//1<br> cnode:=tv1.Items.AddChild(Node,hstr );<br> cnode.ImageIndex :=0;<br> cnode.SelectedIndex :=cnode.ImageIndex;<br> end;//1<br> end;//22<br> end;//4<br><br>end;<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>var<br> s:string;<br>begin<br> tv1.Items.Clear ;<br> s:=edit1.Text ;<br> dispdir4(s,nil);<br> tv1.FullExpand ;<br> tv1.SortType :=stText;<br> tv1.AlphaSort();<br>end;<br>