Search code examples
vbscriptaccess-denied

vbscript to preserve access denial file while in remove process


I have a problem while I try to remove some folder/file in one specify folder on a server with a limit time, and some of folder/file can't remove and preserve some folder/file while they are in access denial status, can vbs do it?


Solution

  • I answer your question in your comment here, because more space to write :)

    If you want to access and this fails then VBscript raise an error. Your script stop working. Solution here is to implement an error handling. So what you can do is to move that part into a sub routine or function and activate On Error Resume Next like this:

    Sub DeleteFolder(p_sFolder)
      Err.Clear
      On Error Resume Next
    
      Dim fso : Set fso = CreateObject("scripting.FileSystemObject")
      Dim deletefolder : Set deletefolder = fso.GetFolder(p_sFolder)
      deletefolder.Delete(True) 
      Set fso = Nothing
    
      If Err.Number<>0 THen
        Wscript.Echo Err.Number
        Wscript.Echo Err.Description
        ' here you can handle with the error with additional code
      End If
    
    End Sub