Link to home
Start Free TrialLog in
Avatar of cahillj
cahilljFlag for United States of America

asked on

VBscript editing, my script bombs out when going to a folder it doesnt have rights to. need to be able to skip it

i have a code below.   it goes through all the folders but when it gets to the folder it doesnt have rights to, it gets killed.   i want it to be skip that folder it doesnt have right to and move to the next folders....
Set objShell = CreateObject("WScript.Shell")
strProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strFolder = strProfile & "Cookies"
intDaysOld = 60
dteDate = DateAdd("d", intDaysOld, Now)
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strFolder).Files
	If objFile.DateLastModified < dteDate Then
		On Error Resume Next
		objFSO.DeleteFile objFile.Path, True
		Err.Clear
		On Error GoTo 0
	End If
Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tigermatt
tigermatt
Flag of United Kingdom of Great Britain and Northern Ireland image

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 cahillj

ASKER

thank you!