'显示插入逻辑卷根目录的文件名列表,需要在工程里引用Microsoft Scripting Runtime库。
Function ListFiles(strPath As String, ByRef list As ListBox)
Dim fso As New Scripting.FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Set objFolder = fso.GetFolder(strPath)
For Each objFile In objFolder.Files
list.AddItem objFile.Name
Next
End Function
Sub getFileName()
Dim i As Long
Dim fso As Object
Dim strFolderPath As String
Dim objFolder As Object
Dim objFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
strFolderPath = "D:\wu"
Set objFolder = fso.GetFolder(strFolderPath)
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
Debug.Print objFile.Name
Next
End If
Set objFile = Nothing
Set objFolder = Nothing
Set fso = Nothing
End Sub