vb 遍历文件夹 与遍历文件

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


 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值