Solved

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

Posted on 2008-10-10
2
200 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:cahillj
2 Comments
 
LVL 58

Accepted Solution

by:
tigermatt earned 500 total points
ID: 22688525
Try just adding an "on error resume next" to the top of the script. When it crashes on a particular folder, it will just move onto the next one without erroring.

-tigermatt
on error resume next

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

0
 

Author Closing Comment

by:cahillj
ID: 31505084
thank you!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now