Link to home
Start Free TrialLog in
Avatar of tonyjoewalker
tonyjoewalker

asked on

VBScript Delete Folder Error

Hi

I have a working VBScript that deletes old symantec AV defs from servers that have less than 3 GB free on the C drive.  On a couple of servers, the old virus defs are locked by the service and they can't be deleted.  The obvious solution is to stop the service, then delete the folder in question.  Everything else in the script works perfectly.

What I have done is added If err.number <> 0 then call a sub that will stop the service, delete folder, start service (right now it just echos an ERROR line).

What I am running into is that when the script attempts to delete the file, gets an error, and then script then jumps to the next server in the list, so it never gets to the line with if err.number <> 0.  It also doesn't finish checking the rest of the files in that folder.  On Error Resume Next is set at the beginning of the script.

Here is the part of the code in question:

If oSubFolder.Name <> oNewestFolder Then
      Wscript.Echo "Deleting : " & oSubFolder.Name
      ResFile.writeline vbtab & vbtab & "DELETING " & oSubFolder.Name & vbtab & oSubfolder.DateCreated & vbtab & oSubfolder.size
      oSubfolder.Delete, True
      IF Err.number <> 0 Then
            Call StopService(strcomputer)
      END IF
End If

SUB StopService(strComputer)

wscript.echo vbtab & vbtab & "*ERROR*  Need to stop Symantec Service"
ResFile.writeline vbtab & vbtab & "*ERROR*  Need to stop Symantec Service"

END SUB
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonyjoewalker
tonyjoewalker

ASKER

DOH!  I knew that.  :)  I'll test that out.... thanks!
Yup, that did the trick.  Thank you.
Welcome, glad that was it.

~bp