Script stops on protected files such as system files

前端 未结 4 1973
轮回少年
轮回少年 2021-01-26 11:19

This code stops after a while due to protected files such as system files, \"Permission Denied\".

Is there a way to modify the code below so that it can handle such prot

4条回答
  •  情深已故
    2021-01-26 12:07

    I've simplified your code (based upon your duplicate question) and without trying to handle errors I can see a problem: objDIR.SubFolders fails when one of the subfolders (such as \System Volume Information) doesn't have permissions to be viewed! You need to use another method on Folder to enumerate the foldernames, combine them with the existing path and then trap the error .GetFolder may cause when you don't have permissions. (I don't have time to code that solution at the moment.)

    Option Explicit
    
    Dim objFS
    Dim objArgs
    Dim strFolder
    Dim objFolder
    
    Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
    WScript.StdOut.WriteLine """Full Path"",""File Size""," & _
      """File Date modified"",""File Date Created""," & _
      """File Date Accessed"""
    Set objArgs = WScript.Arguments
    strFolder = objArgs(0)
    Set objFolder = objFS.GetFolder(strFolder)
    Go objFolder
    Sub Go(objDIR)
      Dim strFile
      On Error Resume Next
        For Each eFolder in objDIR.SubFolders
            Go eFolder
        Next
        For Each strFile In objDIR.Files
            WScript.StdOut.WriteLine """" & strFile.Path & """,""" & _
              strFile.Size & """,""" & _
              strFile.DateLastModified & """,""" & _
              strFile.DateCreated & """,""" & _
              strFile.DateLastAccessed & """"
        Next
    End Sub
    

提交回复
热议问题