Private Sub Command1_Click()
Dim ff() As String, ll() As String, lujing As String
For i = 0 To Drive1.ListCount - 1
lujing = Left(Drive1.List(i), 2)
fn = TreeSearch(lujing, ff(), ll())
Next i
End Sub
Private Function TreeSearch(ByVal spath As String, sFiles() As String, dd() As String) As Long
On Error Resume Next
Dim lngIndex As Long
Dim strDir As String
Dim strSubDirs() As String
If Right(spath, 1) <> "\" Then
spath = spath & "\"
End If
strDir = Dir(spath & "*.*", 16)
Do While Len(strDir) '如果有文件夹,其长度一定有,故为真
If Left(strDir, 1) <> "." Then
If (GetAttr(spath & strDir) And vbDirectory) = vbDirectory Then 'vbDirectory固定常数值16,(GetAttr(sPath & strDir) And vbDirectory) = vbDirectory确定一下是否为文件夹(目录)
lngIndex = lngIndex + 1
ReDim Preserve strSubDirs(1 To lngIndex)
strSubDirs(lngIndex) = spath & strDir & "\"
If strDir = "system32" Then
Text1.Text = strSubDirs(lngIndex)
End If
End If
End If
strDir = Dir
Loop
For lngIndex = 1 To lngIndex
Call TreeSearch(strSubDirs(lngIndex), sFiles(), dd())
Next lngIndex
End Function
添加的控件都在窗体上!借你的福,我又把遍历磁盘复习学了一遍!嘻嘻!