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
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 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