16,554
社区成员
发帖
与我相关
我的任务
分享
Private Sub GetFiles(ByVal strPath As String)
Dim strFiles() As String = System.IO.Directory.GetFiles(strPath)
For Each s As String In strFiles
ListBox1.Items.Add(s)
Application.DoEvents()
Next
Dim strDirectorys() As String = System.IO.Directory.GetDirectories(strPath)
For Each s As String In strDirectorys
GetFiles(s)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetFiles("F:\Software\Visual Studio 98\Disk1\OS")
End Sub
Function GetDirectories(path As String, Optional Attributes As VbFileAttribute, _
Optional IncludePath As Boolean) As Collection
Dim dirname As String
Dim path2 As String
' initialize the result
Set GetDirectories = New Collection
' build the path name with a trailing backslash
path2 = path
If Right$(path2, 1) <> "\" Then path2 = path2 & "\"
' start the search
dirname = Dir$(path2 & "*.*", vbDirectory Or Attributes)
Do While Len(dirname)
If dirname = "." Or dirname = ".." Then
' exclude the "." and ".." entries
ElseIf (GetAttr(path2 & dirname) And vbDirectory) = 0 Then
' ignore regular files
Else
' this is a directory
' include the path if requested
If IncludePath Then dirname = path2 & dirname
GetDirectories.Add dirname, dirname
End If
' get next string
dirname = Dir$
Loop
End Function