如何用VB获得某一目录下的所有文件和文件夹名称

如何用VB获得某一目录下的所有文件和文件夹名称(要绝对路径) ,
然后把它保存到数组中
网上粘的就不要乱贴了,看不懂,不稀罕
最好写个简单,易懂的,用什么控件要说明,
本人没什么基础,怕看不懂,谢了

Dim a() As String
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Label1.Caption = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo err1
Dir1.Path = Drive1.Drive
Exit Sub
err1:
MsgBox Err.Description, vbInformation + vbOKOnly, "提示"
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim ifieldcount As Integer, irecordcount As Integer
Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
If Option2.Value = True Then
ReDim a(1 To File1.ListCount)
For i = 1 To File1.ListCount
b = File1.List(i)
a(i) = b
Next
End If
If Option1.Value = True Then
ReDim a(1 To Dir1.ListCount)
For i = 1 To Dir1.ListCount
b = Dir1.List(i)
a(i) = b
Next
End If
End Sub

这段程序 复制过去 就行了 创建的控件有 两个option 让你选择 要提取文件夹 还是文件路径的 选中option 1 就是提取文件夹的 option2 就是提取文件的 然后再创建 Drive1 Dir1 File1 这三个 选择文件路径的 控件 再加一个 command 按钮 就行了 有疑问再联系我!!!!!这个 只是 文件路径 你看看 是你想要的话 我再给你写 提取文件夹和文件名的代码!!!!
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-18
  ' Part I查找该文件夹的所有文件
    For Each f In fd.Files
        If UCase(f.Name) = UCase(FileName) Then '查找文件。
            Debug.Print f.Path
            List1.AddItem f.Path
        End If
        DoEvents
    Next
    ' Part II递近查找所有子文件夹
    For Each sfd In fd.SubFolders
        FindFile sfd, FileName  ' 循环查找
    Next
End Sub

相似回答