VB 枚举指定盘符下的某类型文件(包括子目录)?

来源:百度知道 编辑:UC知道 时间:2024/05/26 03:34:45
如题
例如我要在ListBox里显示D盘(包括子目录)里所有的MP3文件的路径
谢谢!

这个是查找指定类型文件的函数,你调用下:
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(lngIn