FILE_ATTRIBUTE_DIRECTORY解决了(1分)

  • 主题发起人 主题发起人 visual_cjiajia
  • 开始时间 开始时间
V

visual_cjiajia

Unregistered / Unconfirmed
GUEST, unregistred user!
FILE_ATTRIBUTE_DIRECTORY解决了<br><br>procedure TForm2.dispdir4(spath:string;node:TTreeNode);<br>var<br>&nbsp;cnode:TTreeNode;<br>&nbsp;ffd:WIN32_FIND_DATA ;<br>&nbsp;hFind:THandle;<br>&nbsp;Dest:string;<br>&nbsp;hstr:string;<br>&nbsp;hwstr:string;<br>begin<br>if copy(spath,length(spath),1)&lt;&gt;'/' then<br>&nbsp; &nbsp;spath:=spath+'/';<br>Dest:=Spath+'*.*';<br><br>&nbsp; hFind:=FindFirstFile(PChar(Dest),ffd);<br>&nbsp; if hFind&gt;0 then<br>&nbsp; &nbsp;begin//1<br>&nbsp; &nbsp; hstr:=ffd.cFileName;<br>&nbsp; &nbsp; hwstr:=Spath+hstr;<br>&nbsp; &nbsp; &nbsp;if (ffd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)&gt;0 then<br>&nbsp; &nbsp; &nbsp; begin//2<br>&nbsp; &nbsp; &nbsp; &nbsp;if (ffd.cFileName[0]&lt;&gt;'.')and (ffd.cFileName[0]&lt;&gt;'..') then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin//3<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode:=tv1.Items.AddChild(Node,hstr );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode.ImageIndex :=1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode.SelectedIndex :=cnode.ImageIndex;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispdir4( spath+hstr ,cnode);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;//3<br>&nbsp; &nbsp; &nbsp; end//2<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; begin//22<br>&nbsp; &nbsp; &nbsp; &nbsp; if extractfileext(hwstr)='.lnk' then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin//1<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode:=tv1.Items.AddChild(Node,hstr );<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode.ImageIndex :=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode.SelectedIndex :=cnode.ImageIndex;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;//1<br>&nbsp; &nbsp; &nbsp; end;//22<br>&nbsp; end;//1<br>&nbsp;while FindNextFile(hFind,ffd)=true &nbsp;do<br>&nbsp; begin//4<br>&nbsp; &nbsp;hstr:=ffd.cFileName;<br>&nbsp; &nbsp;hwstr:=Spath+hstr;<br>&nbsp; &nbsp;if (ffd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)&gt;0 then<br>&nbsp; &nbsp; &nbsp; begin//2<br>&nbsp; &nbsp; &nbsp; &nbsp;if (ffd.cFileName[0]&lt;&gt;'.')and (ffd.cFileName[0]&lt;&gt;'..') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin//3<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode:=tv1.Items.AddChild(Node,hstr );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode.ImageIndex :=1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnode.SelectedIndex :=cnode.ImageIndex;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispdir4( spath+hstr,cnode);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;//3<br>&nbsp; &nbsp; &nbsp; end//2<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; begin//22<br>&nbsp; &nbsp; &nbsp; &nbsp; if extractfileext(hwstr)='.lnk' then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin//1<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode:=tv1.Items.AddChild(Node,hstr );<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode.ImageIndex :=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; cnode.SelectedIndex :=cnode.ImageIndex;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;//1<br>&nbsp; &nbsp; &nbsp; end;//22<br>&nbsp; end;//4<br><br>end;<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>var<br>&nbsp;s:string;<br>begin<br>&nbsp;tv1.Items.Clear ;<br>&nbsp;s:=edit1.Text ;<br>&nbsp;dispdir4(s,nil);<br>&nbsp;tv1.FullExpand ;<br>&nbsp;tv1.SortType :=stText;<br>&nbsp;tv1.AlphaSort();<br>end;<br>
 
以上代码我收藏了,顺便问一句,dispdir4(s,nil)<br>s和nil是分别代表路径和文件名吗,给个详细的使用例了好吗?<br>nil是不是可以使用通配符"?" 和"*".<br>
 
s,路径名:F:/Program Files<br>nil是空指针,这个参数是treeview控件的节点<br>如可以传:treeview1.items.item[0];<br>详细的使用例:dispdir4('F:/Program Files',treeview1.selected);<br>
 

Similar threads

I
回复
0
查看
548
import
I
I
回复
0
查看
738
import
I
I
回复
0
查看
708
import
I
I
回复
0
查看
740
import
I
后退
顶部