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
202 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 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

11 Experts available now in Live!

Get 1:1 Help Now