我用TreeView做的一个资源管理器,源码为:
On Error Resume Next
Dim DriverCount As Integer
Dim GivePath As String
''创建根节点
Set nodx = TreeView1.Nodes.Add(, , "本人电脑", "本人电脑")
For DriverCount = 1 To Drive1.ListCount - 3
GivePath = Left(Drive1.List(DriverCount), 2) + "\"
Set nodx = TreeView1.Nodes.Add("本人电脑", tvwChild, GivePath, GivePath)
 'nodx.Expanded = True
 nodx.Sorted = True
''把各盘的文件夹进行展开放于TreeView1控件中
 SSplitNode GivePath
Next DriverCount
End SubSub SSplitNode(sGivePath As String) ''子过程
''把给定目录下的子目录及子文件全部加入Node对象中
Dim SDI As Integer
Dim SDF As Integer
Dim SDCount As Integer
''用于存放给定目录的下级子目录,该变量数组随递归过程调用而发生变化
Dim SDFile As Integer
'用于记录该目录下的子文件数
Dim GivePathSubDir() As String
''如有则展开目录并放入TreeView1控件中
Dim GivePathSubFile() As String
Dir1.Path = sGivePath
 SDCount = Dir1.ListCount
 File1.Path = sGivePath
SDFile = File1.ListCount
If SDCount <> 0 Then
ReDim GivePathSubDir(SDCount)
SubSaveSubdir sGivePath, GivePathSubDir, SDCount
End If
If SDFile <> 0 Then
ReDim GivePathSubFile(SDFile)
''把下级目录放入变量数组GivePathSubDir中
SubFile sGivePath, GivePathSubFile, SDFile
End If
''即为递归出口。否则会形成死循环。
If SDCount = 0 And SDFile = 0 Then Exit Sub
For SDI = 0 To SDCount - 1
Set nodx = TreeView1.Nodes.Add(sGivePath, tvwChild, GivePathSubDir(SDI), FOnlyPath(GivePathSubDir(SDI)))
nodx.Sorted = True
Next SDI
For SDF = 0 To SDFile - 1
Set nodx = TreeView1.Nodes.Add(sGivePath, tvwChild, GivePathSubFile(SDF), FOnlyPath(GivePathSubFile(SDF)))
nodx.Sorted = True
Next SDF
''调用递归(子程序自己调用自己)
For SDI = 0 To SDCount - 1
sGivePath = GivePathSubDir(SDI)
SSplitNode sGivePath
Next SDI
End SubSub SubSaveSubdir(fgivepath As String, fGivePathSubDir() As String, fSDCount As Integer)
''fGivePath 给定目录串
''fGivePathSubDir 用于存放子目录
''fSDCount 子目录数
Dim i As Integer
Dim t As Integer
Dir1.Path = fgivepath
t = Dir1.ListCount
For i = 0 To t - 1
fGivePathSubDir(i) = Dir1.List(i)
Next i
fSDCount = t
End Sub
Sub SubFile(fgivepath As String, fGivePathSubFile() As String, fSDFile As Integer)
''fGivePath 给定目录串
''fGivePathSubDir 用于存放子目录
''fSDCount 子目录数
Dim i As Integer
Dim t As Integer
File1.Path = fgivepath
t = File1.ListCount
For i = 0 To t - 1
fGivePathSubFile(i) = File1.List(i)
Next i
fSDFile = t
End Sub
Function FOnlyPath(DString As String) As String
''功能是去掉上级目录,只留下当前目录名
''DString为给定的全路径目录名
If DString = "" Then Exit Function
Dim DLength As Integer
DLength = Len(DString)
Dim DD As Integer
For DD = DLength To 1 Step -1
If Mid(DString, DD, 1) = "\" Then Exit For
Next DD
FOnlyPath = Mid(DString, DD + 1)
End Function
e,f,g盘的子文件夹只能显示,不能打开下一级子文件夹。
c,d只有第一个字文件夹可以显示,其他的子文件夹不能显示
请教大侠,帮忙解决!