如何使用 VB6 获取目录中所有文件名的列表?

发布于 2024-07-09 03:34:26 字数 46 浏览 6 评论 0原文

VB6中循环遍历指定文件夹目录中的所有文件并获取它们的名称的最简单方法是什么?

What is the simplest way in VB6 to loop through all the files in a specified folder directory and get their names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

拔了角的鹿 2024-07-16 03:34:26
sFilename = Dir(sFoldername)

Do While sFilename > ""

  debug.print sFilename 
  sFilename = Dir()

Loop
sFilename = Dir(sFoldername)

Do While sFilename > ""

  debug.print sFilename 
  sFilename = Dir()

Loop
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
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
雨的味道风的声音 2024-07-16 03:34:26

DJ 的解决方案 简单而有效,如果您需要 FileSystemObject 可以提供的更多功能(需要引用 Microsoft Scripting Runtime),只需扔掉另一个即可。

Dim fso As New FileSystemObject
Dim fil As File

For Each fil In fso.GetFolder("C:\").Files
  Debug.Print fil.Name
Next

DJ's solution is simple and effective, just throwing out another one in case you need a little more functionality that the FileSystemObject can provide (requires a reference to the Microsoft Scripting Runtime).

Dim fso As New FileSystemObject
Dim fil As File

For Each fil In fso.GetFolder("C:\").Files
  Debug.Print fil.Name
Next
十六岁半 2024-07-16 03:34:26

'对于 VB6 来说非常棘手:
'只需获取保存在磁盘/项目目录中的所有项目 .frm 文件的位置

Dim CountVal As Integer
计数值 = 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

'For VB6 very Tricky:
'Simply get the location of all project .frm files saved in your disk/project directory

Dim CountVal As Integer
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
格子衫的從容 2024-07-16 03:34:26

创建名称为 browserButton 的按钮
创建名称为 List1 的文件列表框,

双击设计中的按钮

,代码应该如下所示,

Private Sub browseButton_Click()

Dim path  As String
path = "C:\My Folder"

List1.path() = path
List1.Pattern = "*.txt"
End Sub

现在运行它

create button with name = browseButton
create filelistbox with name = List1

double click on button in design

and code should look like this

Private Sub browseButton_Click()

Dim path  As String
path = "C:\My Folder"

List1.path() = path
List1.Pattern = "*.txt"
End Sub

done now run it

黯然#的苍凉 2024-07-16 03:34:26

您可以使用以下演示代码,

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

You can use the following demo code,

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文