高手指教,用下面程序搜索扩展名为txt的文件后,For Each tFil In fld.Files出现“拒绝的权限”的错误,为

2020-09-03 教育 84阅读
由于你访问到了根目录下的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
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com