这是一个利用循环搜索原理来遍历目录中的所有文件的过程,非常实用,本人收藏改进后经常使用,遗憾的是很难考证谁是原创.再次声明本人只是对其中部分稍加修改.
' 功能:遍历目录中的所有文件(包括子目录) ' 特点:非API函数,可扩展,如是否包括子目录及限定文件后缀名等 Public Function SearchPath(ByVal sPath As String, ListBoxCon As ListBox) As Boolean Dim sChildDir() As String Dim sFileName As String Dim lDirNum As Long Dim lCount As Long On Error GoTo SearchPathErr If Right(sPath, 1) <> "\" Then sPath = sPath + "\" sFileName = Dir(sPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly) While sFileName <> "" DoEvents If (GetAttr(sPath + sFileName) And vbDirectory) = vbDirectory Then If sFileName <> "." And sFileName <> ".." Then ReDim Preserve sChildDir(lDirNum) As String sChildDir(lDirNum) = sFileName lDirNum = lDirNum + 1 End If Else ListBoxCon.AddItem sPath + sFileName End If sFileName = Dir Wend For lCount = 0 To lDirNum - 1 Call SearchPath(sPath + sChildDir(lCount), ListBoxCon) Next Erase sChildDir SearchPath = True Exit Function SearchPathErr: SearchPath = False End Function
|
阅读(323) | 评论(0) | 转发(0) |