VB获取文件名

场景:VB获取文件名解决办法

VB获取文件名
有2个问题对于某些人应该小菜:
1、获取某地址下所有文件夹名称(不带路径),添加到Combox1
2、获取Combox1选中的文件夹里的所有TXT文件,添加到Combox2

------解决方案--------------------
Private Sub Command1_Click()
    Dim fo As New Scripting.FileSystemObject
    
    Dim fp As Scripting.Folder
    Dim fs As Scripting.Folder
    
    Set fp = fo.GetFolder("e:")
    For Each fs In fp.SubFolders
        MsgBox fs.Name
    Next
    
End Sub

------解决方案--------------------
Dim d As String
Private Sub Combo1_Click()
    Dim fo, fp, fs
    Set fo = CreateObject("Scripting.FileSystemObject")
    Set fp = fo.GetFolder(d + "\" + Combo1.Text)
    Combo2.Clear
    For Each fs In fp.Files
        If LCase(Right(fs.Name, 4)) = ".txt" Then
            Combo2.AddItem fs.Name
        End If
    Next
    Combo2.ListIndex = 0
    Set fs = Nothing
    Set fp = Nothing
    Set fo = Nothing
End Sub

Private Sub Command1_Click()
    Dim fo, fp, fs
    d = "d:"
    Set fo = CreateObject("Scripting.FileSystemObject")
    Set fp = fo.GetFolder(d)
    Combo1.Clear
    For Each fs In fp.SubFolders
        Combo1.AddItem fs.Name
    Next
    Combo1.ListIndex = 0
    Set fs = Nothing
    Set fp = Nothing
    Set fo = Nothing
End Sub