dir()递归即可:
Private Sub Command1_Click()
Listfiles "d:/JAVA", List1
End Sub
Sub Listfiles(ByVal mydir As String, ByVal filelist As ListBox)
Dim i As Long, dirlevel As Long, fname As String, dirlist() As String
mydir = IIf(Right(mydir, 1) = "/", mydir, mydir & "/")
fname = Dir(mydir)
Do While fname <> ""
filelist.AddItem mydir & fname
fname = Dir
Loop
fname = LCase(Dir(mydir, vbDirectory))
Do While fname <> ""
If fname <> "." And fname <> ".." Then
If GetAttr(mydir & fname) And vbDirectory Then
dirlevel = dirlevel + 1
ReDim Preserve dirlist(dirlevel)
dirlist(dirlevel) = mydir & fname
End If
End If
fname = Dir
DoEvents
Loop
For i = 1 To dirlevel
Listfiles dirlist(i) & "/", filelist
Next
End Sub
Private Sub Command1_Click()
Listfiles "d:/JAVA", List1
End Sub
Sub Listfiles(ByVal mydir As String, ByVal filelist As ListBox)
Dim i As Long, dirlevel As Long, fname As String, dirlist() As String
mydir = IIf(Right(mydir, 1) = "/", mydir, mydir & "/")
fname = Dir(mydir)
Do While fname <> ""
filelist.AddItem mydir & fname
fname = Dir
Loop
fname = LCase(Dir(mydir, vbDirectory))
Do While fname <> ""
If fname <> "." And fname <> ".." Then
If GetAttr(mydir & fname) And vbDirectory Then
dirlevel = dirlevel + 1
ReDim Preserve dirlist(dirlevel)
dirlist(dirlevel) = mydir & fname
End If
End If
fname = Dir
DoEvents
Loop
For i = 1 To dirlevel
Listfiles dirlist(i) & "/", filelist
Next
End Sub