一个函数能实现的话,我也想要....呵呵
这个写起来还是很复杂的...给你一个函数,你举一反三吧
给你一个递归调用VB自带函数查找文件的函数TreeSearch。
Public Function TreeSearch(ByVal sPath As String, ByVal sFileSpec As String, sFiles() As String) As Long
Static lngFiles As Long '文件数目
Dim sDir As String
Dim sSubDirs() As String '存放子目录名称
Dim lngIndex As Long
Dim lngTemp&
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir(sPath & sFileSpec)
'获得当前目录下文件名和数目
Do While Len(sDir)
lngFiles = lngFiles + 1
ReDim Preserve sFiles(1 To lngFiles)
sFiles(lngFiles) = sPath & sDir
sDir = Dir
Loop
'获得当前目录下的子目录名称
lngIndex = 0
sDir = Dir(sPath & "*.*", vbDirectory)
Do While Len(sDir)
If Left(sDir, 1) <> "." And Left(sDir, 1) <> ".." Then '' 跳过当前的目录及上层目录
'找出子目录名
If GetAttr(sPath & sDir) And vbDirectory Then
lngIndex = lngIndex + 1
'保存子目录名
ReDim Preserve sSubDirs(1 To lngIndex)
sSubDirs(lngIndex) = sPath & sDir & "\"
End If
End If
sDir = Dir
Loop
For lngTemp = 1 To lngIndex
'利用递归方法查找每一个子目录下文件
Call TreeSearch(sSubDirs(lngTemp), sFileSpec, sFiles())
Next lngTemp
TreeSearch = lngFiles
End Function
[[it] 本帖最后由 不说也罢 于 2008-12-15 17:44 编辑 [/it]]