→→→→→→→请教,这个搜索模块,如果我只想搜索"文件夹"而不要"文件"的话,要怎么修改一下?
坛子里高人老马的搜索模块,如果我只想搜索"文件夹"名称而不要"文件"名称的话,要怎么修改一下?谢谢!--------------------编程问答-------------------- --------------------编程问答-------------------- 谢谢大侠,不过我是想要搜索.
Option Explicit
Public Declare Sub Sleep Lib "kernel32 " (ByVal dwMilliseconds As Long)
Private FoundFile() As String '存放传回值的字串阵列
Private Ntx As Long
Public Function SearchFileInPath(ByVal thePath As String, ByVal theFileName As String, Optional ByVal mStop As Boolean = False) As String()
If Right(thePath, 1) <> "\" Then thePath = thePath & "\"
Call GetFileLoop(thePath, theFileName, mStop)
SearchFileInPath = FoundFile
End Function
Private Function GetFileLoop(CurrentPath As String, ByVal SearFile As String, Optional ByVal mStop As Boolean = False) As String
Dim nI As Integer, nDirectory As Integer, i As Long
Dim sFileName As String, sDirectoryList() As String
' Ntx = 0
On Error Resume Next
sFileName = Dir(CurrentPath, vbHidden Or vbDirectory Or vbReadOnly Or vbSystem)
Do While sFileName <> ""
If UCase(sFileName) Like UCase(SearFile) Then
i = GetAttr(CurrentPath + sFileName)
If (i And vbDirectory) = 0 Then
If mStop = False Then
ReDim Preserve FoundFile(Ntx)
FoundFile(Ntx) = CurrentPath + sFileName
Ntx = Ntx + 1
DoEvents
Sleep 5
Else
GetFileLoop = CurrentPath + sFileName
Exit Function
End If
End If
End If
If sFileName <> "." And sFileName <> ".." Then
If GetAttr(CurrentPath & sFileName) _
And vbDirectory Then
nDirectory = nDirectory + 1
ReDim Preserve sDirectoryList(nDirectory)
sDirectoryList(nDirectory) = CurrentPath & sFileName
End If
End If
sFileName = Dir
Loop
For nI = 1 To nDirectory
GetFileLoop = GetFileLoop(sDirectoryList(nI) & "\", SearFile)
If GetFileLoop <> "" And mStop = True Then Exit For
Next nI
End Function
那我是先不管三七二十一都先搜,文件和文件夹都搜.然后判断If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
吗?但是这样好像效率低了, 我等于说只要搜文件夹,那些文件我完全不需要搜的,搜的话相当于做了很多无用功.
补充:VB , 基础类