vb 如何获取文件夹列表,显示在ListBox中,并将文件夹名称作为变量
展开全部
文件夹名称存在 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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询