如题所述
Sub 获得文件夹列表()
Dim f
f = Dir("D:\aaa\", 16) '在括号内输入你指定的目录
Do While f <> ""
If InStr(f, ".") = 0 Then
ListBox1.AddItem f
End If
f = Dir ' 查找下一个目录
Loop
End Sub
Dim f
f = Dir("D:\aaa\", 16) '在括号内输入你指定的目录
Do While f <> ""
If InStr(f, ".") = 0 Then
ListBox1.AddItem f
End If
f = Dir ' 查找下一个目录
Loop
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-07-23
文件夹名称存在 sSub 数组中。
Public Sub Search(ByVal sPath As String)
Static lngFiles As Long
Dim sDir As String
Dim sSub() As String
Dim lngIndex As Long
Dim lngTemp&
DoEvents
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
lngIndex = 0
sDir = Dir(sPath & "*.*", vbDirectory)
Do While Len(sDir)
DoEvents
If Left(sDir, 1) <> "." And Left(sDir, 1) <> ".." Then
If GetAttr(sPath & sDir) And vbDirectory Then
lngIndex = lngIndex + 1
ReDim Preserve sSub(1 To lngIndex)
sSub(lngIndex) = sPath & sDir
List1.AddItem sSub(lngIndex)
DoEvents
End If
End If
sDir = Dir
Loop
End Sub
Private Sub Command1_Click()
Search "c:\"
End Sub本回答被提问者和网友采纳
Public Sub Search(ByVal sPath As String)
Static lngFiles As Long
Dim sDir As String
Dim sSub() As String
Dim lngIndex As Long
Dim lngTemp&
DoEvents
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
lngIndex = 0
sDir = Dir(sPath & "*.*", vbDirectory)
Do While Len(sDir)
DoEvents
If Left(sDir, 1) <> "." And Left(sDir, 1) <> ".." Then
If GetAttr(sPath & sDir) And vbDirectory Then
lngIndex = lngIndex + 1
ReDim Preserve sSub(1 To lngIndex)
sSub(lngIndex) = sPath & sDir
List1.AddItem sSub(lngIndex)
DoEvents
End If
End If
sDir = Dir
Loop
End Sub
Private Sub Command1_Click()
Search "c:\"
End Sub本回答被提问者和网友采纳