简体   繁体   English

vbscript跳过将在递归调用中引发权限被拒绝错误的文件夹

[英]vbscript skip folders that will throw Permission Denied Error in recursive call

I am looping thru all folders on my C: drive in windows 7. I am using vbscript. 我正在Windows 7中的C:驱动器上遍历所有文件夹。我正在使用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. 使用严格本地的“下一步继续错误”来测试是否可以访问要处理的文件夹的.Files.Count / .SubFolders.Count。 If not, don't recurse. 如果没有,请不要递归。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM