这样也可以满足你的要求
dim filename as string
filename = Dir("C:\abc\*.txt")
Do While filename <> ""
If filename <> "." And filename <> ".." Then
RichTextBox1.Text =RichTextBox1.Text & filename & vbNewLine
End If
filename = Dir ' 查找下一个文件。
Loop
Public Sub fileconnection(strpath As String, flag As Boolean)
Dim fso As New FileSystemObject
Dim folder As folder
Dim node As node
Set folder = fso.GetFolder(strpath)
Dim f As File
Dim strkey As String
TreeView1.LineStyle = tvwRootLines
strkey = strpath
If flag Then
Else
Set node = TreeView1.Nodes.Add(, , strkey, folder.Path)
End If
Dim sf As folder
If folder.Files.Count > 0 Then
For Each f In folder.Files
TreeView1.Nodes.Add strkey, tvwChild, f.Path, f.Name
Next f
End If
If folder.SubFolders.Count > 0 Then
For Each sf In folder.SubFolders
TreeView1.Nodes.Add strkey, tvwChild, sf.Path, sf.Name
Call fileconnection(sf.Path, True)
Next sf
End If
Set f = Nothing
Set sf = Nothing
End Sub
无需FILEBOX控件:
Private Sub Command1_Click()
richtextbox1.Text = dirs("C:\abc\")
End Sub
Function dirs(ByVal x As String) As String
Dim sfile As String, i As Long
sfile = Dir(x + "*.txt")
dirs = sfile
i = 1
Do While Len(sfile) > 0
sfile = UCase(Trim(sfile))
i = i + 1
sfile = Dir '下一个文件
dirs = dirs & vbCrLf & sfile
Loop
End Function