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
'用API搜索所有文件夹Public Sub FileSearch(ByVal sPath As String)
Static lngFiles As Long
Dim sDir As String
Dim sSubDirs() As String
Dim lngIndex As Long
Dim lngTemp&
DoEvents
If Right(sPath, 1) <搏此>"\" Then sPath = sPath &"\"
DoEvents
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 &"基枯迅\"
List1.AddItem sSubDirs(lngIndex)
DoEvents
End If
End If
sDir = Dir
Loop
End Sub
Private Sub Command1_Click() '测试代码
FileSearch "d:\" '败烂设置初始路径
End Sub
'添加一个按钮,一个列表框,效果很好的,不明白的加我百度HI
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)