VB问题:如何读取、返回某一目录下的所有文件名

VB问题:如何读取、返回某一目录下的所有文件名,第1张

概述控件:按钮一个    列表框一个       Function SearchFiles(Path As String,FileType As String) Dim Files() As String '文件路径 Dim Folder() As String '文件夹路径 Dim a, b, c As Long Dim sPath As String   sPath = Dir(Path & Fi

控件:按钮一个 列表框一个

Function Searchfiles(Path As String,fileType As String)

Dim files() As String '文件路径

Dim Folder() As String '文件夹路径

Dim a,b,c As Long

Dim sPath As String

sPath = Dir(Path & fileType) '查找第一个文件

do while Len(sPath) '循环到没有文件为止

a= a + 1

ReDim Preserve files(1 To a)

files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中

List1.AddItem files(a) '加入List控件中

sPath = Dir '查找下一个文件

DoEvents '让出控制权

Loop

sPath = Dir(Path & "\",vbDirectory) '查找第一个文件夹

do while Len(sPath) '循环到没有文件夹为止

Ifleft(sPath,1) <> "." Then '为了防止重复查找

IfgetAttr(Path & "\" & sPath) And vbDirectory Then '如果是文件夹则。。。。。。

b = b + 1

ReDim Preserve Folder(1 To b)

Folder(b) = Path & sPath & "\" '将目录和文件夹名称组合形成新的目录,并存放到数组中

End If

End If

sPath = Dir '查找下一个文件夹

DoEvents '让出控制权

Loop

For c = 1 To b '使用递归方法,遍历所有目录

Searchfiles Folder(c),fileType

Next

End Function

Private Sub Command1_Click() '调用

Searchfiles "e:\","*.*"

End Sub

总结

以上是内存溢出为你收集整理的VB问题:如何读取返回某一目录下的所有文件名全部内容,希望文章能够帮你解决VB问题:如何读取、返回某一目录下的所有文件名所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1291730.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存