|
-
Feb 26th, 2000, 07:40 AM
#1
Thread Starter
Lively Member
Ok... I need to put a directory with all of its subdirectories and files of a specified type into a TreeView control. Right now I'm adding the Favorites to it, and I'm running into a problem that I'm going to have to limit the amount of subdirectories I can show... How can I do this without limiting the sub directories? Here is my current code which only does all directories under the favorites, and all directories under those directories... yes, its confusing and thats why I'm going insane... here's the code I have:
(Controls:)
Treeview:tFavorites
DirectoryList:dFavorites
FileList:Urls
Note: the FavoritesPath variable is the path of the current users favorites...
Here's the code!:
Code:
Private Sub SetupFavorites()
Dim DirsUnderFavorites As Integer
Dim FavoritesPathLength As Integer
Dim DirectoryLength As Integer
Dim DirectoryName As String
Dim FLoop As Integer
dFavorites.Path = FavoritesPath
Urls.Path = FavoritesPath
DirsUnderFavorites = dFavorites.ListCount - 1
FavoritesPathLength = Len(FavoritesPath)
dFavorites.ListIndex = 0
FLoop = 0
Do Until FLoop = dFavorites.ListCount
With dFavorites
b = Len(.List(.ListIndex))
DirectoryLength = b - FavoritesPathLength
DirectoryName = Right(.List(.ListIndex), DirectoryLength)
tFavorites.Nodes.Add , , FavoritesPath & DirectoryName & ":Folder", DirectoryName, 1, 2
If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
End With
FLoop = FLoop + 1
Loop
Urls.ListIndex = 0
FLoop = 0
Do Until FLoop = Urls.ListCount
With Urls
urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
tFavorites.Nodes.Add , , , urlstring, 3
If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
End With
FLoop = FLoop + 1
Loop
dFavorites.Path = FavoritesPath
MaxDirs = dFavorites.ListCount
bfloop = 0
dFavorites.ListIndex = 0
Do Until bfloop = MaxDirs 'by the way, the bfloop stands for big f--king loop ^_^, floop is favorites loop
With dFavorites
.Path = FavoritesPath
.ListIndex = bfloop
.Path = .List(.ListIndex) 'dfavorites now shows all directories under the first directory under favorites
Urls.Path = .Path 'shows all urls in current favorites path
firstloop = True
looped = False
Do Until .ListIndex = .ListCount - 1
looped = True
'get rid of path for parent directory
b2 = Len(.List(-1))
DirectoryLength2 = b2 - FavoritesPathLength
directoryname2 = Right(.List(-1), DirectoryLength2)
If Urls.ListIndex + 1 < Urls.ListCount Then Urls.ListIndex = 0
.ListIndex = .ListIndex + 1
'get rid of path for current directory
b = Len(.List(.ListIndex))
DirectoryLength = b - FavoritesPathLength - DirectoryLength2 - 1
DirectoryName = Right(.List(.ListIndex), DirectoryLength)
c = Len(.List(.ListIndex))
DirectoryLength3 = c - FavoritesPathLength
DirectoryName3 = Right(.List(.ListIndex), DirectoryLength3)
tFavorites.Nodes.Add FavoritesPath & directoryname2 & ":Folder", tvwChild, FavoritesPath & DirectoryName3 & ":Folder", DirectoryName, 1, 2
Urls.Path = .List(.ListIndex)
FLoop = 0
Do Until FLoop = Urls.ListCount
With Urls
If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
tFavorites.Nodes.Add FavoritesPath & DirectoryName3 & ":Folder", tvwChild, , urlstring, 3
End With
FLoop = FLoop + 1
Loop
If firstloop = True And .ListIndex = .ListCount - 1 Then
FLoop = 0
oldpath = dFavorites.Path
olddex = dFavorites.ListIndex
dFavorites.Path = FavoritesPath
dFavorites.ListIndex = bfloop
Urls.Path = dFavorites.List(dFavorites.ListIndex)
Do Until FLoop = Urls.ListCount
With Urls
If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
tFavorites.Nodes.Add FavoritesPath & directoryname2 & ":Folder", tvwChild, , urlstring, 3
End With
FLoop = FLoop + 1
Loop
firstloop = False
dFavorites.Path = oldpath
dFavorites.ListIndex = olddex
End If
Loop
If looped = False Then
FLoop = 0
Urls.Path = dFavorites.List(dFavorites.ListIndex)
Do Until FLoop = Urls.ListCount
With Urls
If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
tFavorites.Nodes.Add Urls.Path & ":Folder", tvwChild, , urlstring, 3
End With
FLoop = FLoop + 1
Loop
End If
bfloop = bfloop + 1
End With
Loop
End Sub
Ok. I hope someone can help me out... (I'm suprised no one else ran into this problem yet!)...
-Xero
-
Mar 16th, 2000, 05:22 AM
#2
transcendental analytic
Subdirs
This looks like something i tried to solve some years ago...(If it is the directory in directory thing) I don't know what to do about your code, that confuses me too. But i have a control that might help you. Originally it was an example in vb5 help that didn't work correctly. I fixed this and made a control of it. Here's the code. Use the explore pathtofavorites and then all files and dirs will be reported in the two events. Try it
Event Filecatch(File As String, path As String, level As Integer)
Event Direcatch(dire As String, path As String, level As Integer)
Public curlevel As Integer
Public filemax
Public diremax
Public tid
Sub explore(startdir As String, Optional pauses = 100)
tids = Timer
filemax = 0: diremax = 0: Totalb = 0: curlevel = 0
If Right(startdir, 1) <> "\" Then startdir = startdir & "\"
ListSubDirs startdir, pauses
tid = Timer - tids
End Sub
Sub ListSubDirs(path As String, pauses)
Dim i, dmax, dirname As String, dire() As String ' Declare variables.
dirname = Dir(path, 63) ' Get first directory name.
Do While dirname <> ""
If dirname <> "." And dirname <> ".." Then
If Int(GetAttr(path + dirname) / 16) Mod 2 = 1 Then
If (dmax Mod 10) = 0 Then
ReDim Preserve dire(dmax + 10) ' Resize the array.
End If
diremax = diremax + 1: dmax = dmax + 1
dire(dmax) = dirname
RaiseEvent Direcatch(dirname, path, curlevel)
Else
filemax = filemax + 1
RaiseEvent Filecatch(dirname, path, curlevel)
End If
End If
dirname = Dir ' Get another directory name.
waiter = waiter + 1: If waiter Mod (pauses) = 1 Then DoEvents
Loop
For i = 1 To dmax
curlevel = curlevel + 1
ListSubDirs path & dire(i) & "\", pauses
Next i
curlevel = curlevel - 1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|