I am looping thru all folders on my C: drive in windows 7. I am using vbscript. How can I detect if a permission denied error will occur on a folder so that I can skip that folder and keep processing the rest of the folders.
Sub SearchForWsFiles(strFolderPath)
Dim objFolder
Dim objFile
Dim objSubFolder
Set objFolder = objFSO.GetFolder(strFolderPath)
objLogFile.WriteLine(objFolder.Name)
For Each objFile In objFolder.Files
If(objFSO.GetExtensionName(objFile.Name) = "ws") Then
objLogFile.WriteLine(objFile.Name)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Call SearchForWsFiles(objSubFolder.Path)
Next
End Sub
Use a strictly local "On Error Resume Next" to test whether you can access the folder-to be-processed's .Files.Count/.SubFolders.Count. If not, don't recurse.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.