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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

22 Experts available now in Live!

Get 1:1 Help Now