由于你访问到了根目录下的System Volume Information目录,该目录的访问是受限的。你可以对fld进行判断,如果包含该目录就跳过。代码如下:
Private Function FindFile(ByVal sFol As String, sFile As String) As Long
Dim tFld As Folder, tFil As File, FileName As String
Set fld = fso.GetFolder(sFol)
If InStr(1, fld, "System Volume Information") = 0 Then
For Each tFil In fld.Files
If Mid(tFil.Name, InStrRev(tFil.Name, ".") + 1) = Text1 Then _
Text2 = Text2 & fso.BuildPath(fld.path, tFil.Name) & vbCrLf
Text2.SelStart = Len(Text2)
DoEvents
Next
If fld.SubFolders.Count > 0 Then
For Each tFld In fld.SubFolders
DoEvents
FindFile = FindFile + FindFile(tFld.path, sFile)
Next
End If
End If
End Function