'转载请保留 3q2008.com 许仙
'*************************************************************************
' 功能描述:'列举文件夹下的所有文件名,加到数组里 传入变体型返回数组 strFolder 后没用/
'*************************************************************************
Public Function ListFolderFiles(ByRef myArrayFiles, strFolder As String)
Dim strFileName As String
Dim intI As Integer
strFileName = Dir(strFolder & "/")
If strFileName <> "" Then
ReDim myArrayFiles(0) As String
intI = 0
While strFileName <> ""
ReDim Preserve myArrayFiles(intI) As String
myArrayFiles(intI) = strFolder & "/" & strFileName
intI = intI + 1
strFileName = Dir()
Wend
End If
End Function
'*************************************************************************
'列举出文件夹下的所以文件夹 sFolderPath 后要有/
'Print GetFoder("c:/")
'|*|WINDOWS|*|Temp|*|VF|*|Documents and Settings|*|Program Files|*|word知识|*|senty|*|tempdir
'*************************************************************************
Public Function GetFoder(sFolderPath As String)
Dim sFile As String
Dim sFolderName As String
Dim sMainFolder$
'输入的文件夹名
sFile = Dir(sFolderPath, vbDirectory)
If sFile <> "" Then
While sFile <> ""
If GetAttr(sFolderPath & sFile) = vbDirectory Then
If sFile <> "." And sFile <> ".." Then
'获得文件夹后的代码
'Debug.Print sFolderPath & sFile
sFolderName = sFolderName & "|*|" & sFile
GetFoder = sFolderName
End If
End If
sFile = Dir()
Wend
End If
End Function
'列举所以文件夹
'返回用 **分开的文件字符串
Public Function ListFolder(sPath As String) As String
Dim sFileName$, MyMarry
sFileName = Dir(sPath & "/*.*")
Do Until sFileName = ""
If GetAttr(sPath) = vbDirectory Then
ListFolderFiles MyMarry, sFileName
End If
Loop
End Function
这个三个函数,不使用fileSystem组件,叫你列举出文件夹下的所以文件包括子文件夹
不使用fileSystem组件,叫你列举出文件夹下的所以文件包括子文件夹 ,几个月前写的,也没整理,应该是可以正常使用的,使用递归调用就OK了