加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb 遍历文件夹 与遍历文件

发布时间:2020-12-16 22:37:17 所属栏目:大数据 来源:网络整理
导读:Public Sub Search_wenjian() '遍历文件 获得文件名称Dim sPath As String'查找文件夹sPath = Dir(path,vbDirectory) '查找第一个文件夹Do While Len(sPath) '循环到没有文件夹为止 If Left(sPath,1) "." Then '为了防止重复查找 If GetAttr(path "" sPath)
Public Sub Search_wenjian() '遍历文件 获得文件名称

Dim sPath As String
'查找文件夹
sPath = Dir(path,vbDirectory)  '查找第一个文件夹
Do While Len(sPath) '循环到没有文件夹为止
   If Left(sPath,1) <> "." Then '为了防止重复查找
   If GetAttr(path & "" & sPath) And vbDirectory Then '如果是文件夹则。。。。。。
      Folder_num = Folder_num + 1

      'Folder(b) = path & sPath & "" '将目录和文件夹名称组合形成新的目录,并存放到数组中
      Folder_file(Folder_num - 1) = sPath
      'Folder_file_path(Folder_num - 1) = path & sPath & ""
   End If
   End If
 sPath = Dir '查找下一个文件夹
 DoEvents '让出控制权
Loop

End Sub

Public Sub Search_file_in_folder(folder_name As String)  '遍历指定文件夹下的所有文本文件
Dim Files() As String
Dim a As Integer
FileType = "*.*"
sPath = Dir(folder_name & FileType) '查找第一个文件

Do While Len(sPath) '循环到没有文件为止
   a = a + 1
   ReDim Preserve Files(1 To a)
   Files(a) = path & sPath '将文件目录和文件名组合,并存放到数组中

   sPath = Dir '查找下一个文件
   DoEvents '让出控制权
Loop

End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读