VB6循环浏览指定文件夹目录中的所有文件并获取其名称的最简单方法是什么?
答案 0 :(得分:16)
sFilename = Dir(sFoldername)
Do While sFilename > ""
debug.print sFilename
sFilename = Dir()
Loop
答案 1 :(得分:10)
Dim fso As New FileSystemObject
Dim fld As Folder
Dim fil As File
Set fld = fso.GetFolder("C:\My Folder")
For Each fil In fld.Files
Debug.Print fil.Name
Next
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
答案 2 :(得分:4)
DJ的solution简单而有效,如果您需要FileSystemObject可以提供的更多功能(需要引用Microsoft Scripting Runtime),只需抛出另一个。(/ p>
Dim fso As New FileSystemObject
Dim fil As File
For Each fil In fso.GetFolder("C:\").Files
Debug.Print fil.Name
Next
答案 3 :(得分:0)
创建名称为= browseButton的按钮 使用name = List1
创建filelistbox双击设计中的按钮
并且代码应该如下所示
Private Sub browseButton_Click()
Dim path As String
path = "C:\My Folder"
List1.path() = path
List1.Pattern = "*.txt"
End Sub
现在完成运行
答案 4 :(得分:0)
您可以使用以下演示代码
Dim fso As New FileSystemObject
Dim fld As Folder
Dim file As File
Set fld = fso.GetFolder("C:\vishnu")
For Each file In fld.Files
msgbox file.Name
Next
答案 5 :(得分:0)
'对于VB6非常棘手: “只需获取磁盘/项目目录中保存的所有项目.frm文件的位置
将CountVal设置为整数 CountVal = 0 cbo.Clear
sFilename = Dir(App.Path & "\Forms\")
Do While sFilename > ""
If (Right(sFilename, 4) = ".frm") Then
cbo.List(CountVal) = Left(sFilename, (Len(sFilename) - 4))
CountVal = CountVal + 1
End If
sFilename = Dir()
Loop