Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting all files on a drive with the TreeView control

Status
Not open for further replies.

Alt255

Programmer
May 14, 1999
1,846
US
&nbsp;&nbsp;&nbsp;&nbsp;This short subroutine is intended to load a TreeView control with the directory structure and filenames on a drive. It seems to work very well when pointed toward a floppy (no matter how complex the directory structure) but chokes on a hard drive and shows only the files and folders directly off of the root.<br>&nbsp;&nbsp;&nbsp;&nbsp;My error is probably obvious to most but, after playing with this scrap of code for two days, I simply can't see it. If anybody can spot the error, I would be grateful for some guidance.<br><br>Dim nodX As Node<br>On Error Resume Next<br>Driv$ = &quot;A:\&quot;<br>fSpec = vbNormal Or vbReadOnly Or vbHidden Or vbSystem Or vbDirectory<br>Set nodX = TreeView1.Nodes.Add(, , &quot;Root&quot;, Driv$)<br>Folder = 1<br>Do<br>&nbsp;&nbsp;&nbsp;&nbsp;If Folder = 1 Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeEntry$ = Driv$<br>&nbsp;&nbsp;&nbsp;&nbsp;Else&nbsp;&nbsp;'there will be an extra &quot;\&quot;, so remove it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fp$ = TreeView1.Nodes.Item(Folder).FullPath<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeEntry$ = Driv$ + Right$(Fp$, Len(Fp$) - 4)<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Right$(TreeEntry$, 1) = &quot;\&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SrchName$ = Dir(TreeEntry$ & &quot;*.*&quot;, fSpec)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do While SrchName$ &lt;&gt; &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If SrchName$ &lt;&gt; &quot;.&quot; And SrchName$ &lt;&gt; &quot;..&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Son$ = TreeView1.Nodes.Item(Folder).Key + SrchName$<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShowName$ = SrchName$<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (GetAttr(TreeEntry$ & SrchName$) And vbDirectory) = vbDirectory Then ShowName$ = ShowName$ + &quot;\&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Err &lt;&gt; 53 Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'no file not found error, so add a child to the tree<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set nodX = TreeView1.Nodes.Add(TreeView1.Nodes.Item(Folder).Key, tvwChild, Son$, ShowName$)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SrchName$ = Dir<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nodX.EnsureVisible<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;For Chk = Folder + 1 To TreeView1.Nodes.Count 'locate the next folder entry<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Right$(TreeView1.Nodes.Item(Chk).FullPath, 1) = &quot;\&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Folder = Chk<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit For<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;Next<br>&nbsp;&nbsp;&nbsp;&nbsp;If Chk &gt; Folder Then Exit Do&nbsp;&nbsp;'no more folder entries to search<br>Loop<br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top