visual basic 6.0遍历文件夹下所有文件代码

2008-07-18 11:16:16 来源:中国自学编程网 作者:转载 点击:
经常需要的代码,发出来给大家参考一下!

经常需要的代码,发出来给大家参考一下!

'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



logo

本类最新行业评测技巧教程学院
本类热点本日本周本月
本类推荐本日本周本月

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203