vb 如何获取文件夹列表,显示在ListBox中,并将文件夹名称作为变量

如题所述

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本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网