Don't have it right off, but you basically just want to wrap this line in an if 
block

CheckFolder oFSO.GetFolder(sSource)

Something like:
If oFSO.GetFolder(sSource) is not read only
                CheckFolder oFSO.GetFolder(sSource)
End If

That first line isn't correct syntax, but there should be a fairly easy way to 
check that property.

From: Eric Wittersheim [mailto:[email protected]]
Sent: Thursday, December 20, 2012 4:33 PM
To: NT System Admin Issues
Subject: VB Script help needed

I found a VB script to check a folder and all its subfolders for files that are 
older than N days and either report how many files will get deleted if Active = 
True.

The problem I have is that there is a hidden system folder inside of the 
folders that I am searching and I don't want to include that folder in this 
task.  Here is a copy of the script.  Anyone know how to accomplish this?  This 
script will run on a Windows 2008 R2 Server.

Const Active = False
Const sSource = "J:\FTP_Data"
Const MaxAge = 30 'days
Const Recursive = True

Checked = 0
Deleted = 0

Set oFSO = CreateObject("Scripting.FileSystemObject")
if active then verb = "Deleting """ Else verb = "Old file: """
CheckFolder oFSO.GetFolder(sSource)

WScript.echo
if Active then verb = " file(s) deleted" Else verb = " file(s) would be deleted"
WScript.Echo Checked & " file(s) checked, " & Deleted & verb

Sub CheckFolder (oFldr)
For Each oFile In oFldr.Files
Checked = Checked + 1
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
Next

if not Recursive then Exit Sub
For Each oSubfolder In oFldr.Subfolders
CheckFolder(oSubfolder)
Next
End Sub


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to