visualbasic6.0遍历文件夹下所有文件代码

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论

  经常需要的代码,考试大为您整理!
  ’sPath是所查找的文件夹的路径,list是返回的文件列表
  Public Function GetAllFiles(ByVal sPath As String, list As Collection)
  Dim item As String
  Dim oPaths As New Collection
  item = Dir(sPath, vbDirectory)
  While Len(item) > 0
  If item <> "." And item <> ".." Then
  If (GetAttr(FullPathName(sPath) & item) And vbDirectory) = vbDirectory Then
  oPaths.Add item
  Else
  If IsModelFile(item) Then list.Add sPath & item
  End If
  End If
  item = Dir
  Wend
  Dim p
  For Each p In oPaths
  Call GetAllFiles(Combin(sPath, p), list)
  Next
  End Function
  ’判断文件夹后是否有/
  Public Function FullPathName(ByVal strPath As String) As String
  FullPathName = IIf(VBA.Right(strPath, 1) = "/", strPath, strPath & "/")
  End Function
  ’多个文件夹名组成路径
  Public Function Combin(ParamArray arg()) As String
  Dim X
  Dim result As String
  For Each X In arg()
  result = result & FullPathName(X)
  Next
  Combin = result
  End Function

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答