Question

Locked

VBS Delete Script Access Denied

By james.carver ·
Im trying to write a scrip that will allow me to delete the contents of a folder remotely although when it runs accross a file that is locked or in use it errors out and stops. Is there a way to have it skip that one file and move on to the next.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Use "On Error Resume Next"

by cmiller5400 In reply to VBS Delete Script Access ...
Collapse -

Cant use Resume Next

by james.carver In reply to Use "On Error Resume Next ...

I cant use resume next because I am trying to delete the contents of a folder. If i use resume next it will move to the next line in my script. I really need it to just move to the next file if possible. Below is a copy of what I have so you can get an Idea of what im working with.

dim message, title, wackwack, path, windows, temp, history, temporary_internet_files, temp_delete, history_delete, temporary_internet_files_delete

message = "Enter the Service Tag of the PC you want to clean."
title = "PC Cleaner"
wackwack = "\\"
path = "\C$\Documents and Settings\"
windows = "\C$\WINDOWS\temp\*"
temp = "\local settings\temp"
temporary_internet_files = "\local settings\Temporary Internet Files"
temp_delete = "\local settings\temp\*"
temporary_internet_files_delete = "\local settings\Temporary Internet Files\*"

servicetag=InputBox(message, title)

Set fso = CreateObject("Scripting.FileSystemObject")

Set folder = fso.GetFolder(wackwack & servicetag & path)

Set subFolders = folder.SubFolders

For Each folderObject in SubFolders

If fso.FolderExists(wackwack & servicetag & path & folderobject.name & temp) Then
fso.DeleteFolder wackwack & servicetag & path & folderobject.name & temp_delete, True
fso.DeleteFile wackwack & servicetag & path & folderobject.name & temp_delete, True
End If

If fso.FolderExists(wackwack & servicetag & path & folderobject.name & temporary_internet_files) Then
fso.DeleteFolder wackwack & servicetag & path & folderobject.name & temporary_internet_files_delete, True
fso.DeleteFile wackwack & servicetag & path & folderobject.name & temporary_internet_files_delete, True
End If

Next

fso.deletefolder wackwack & servicetag & windows,True
fso.DeleteFile wackwack & servicetag & windows, True

Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing

Back to Software Forum
3 total posts (Page 1 of 1)  

Software Forums