Hello friends,

I have written a script that goes through folder looking for a
sub-folder named "Cookies". If it filnds Cookies then it will enumarate
all files in that folder and delete te files which are older than 7
days.

I want to implemnet error handling where it reports what is wrong if it
cannot perform the above mentioned functions and contunie with the
loop. It displays the error message if there is a directory permmission
related issue and exits the script rather than going through it. Can
youplease point out the error?

As you see I have implemented On Error Resume Next ststement pretty
much in every loop just for troubleshooting but I really cannot
pinpoint where it is not working


__________________________________________________________________________

Dim objShell, objFSO, sUserProfile, objUserProfile, sAppDataFolder,
sUserDir, SFolders Dim sAppData, objDocsAndSettings, objUser, IDate,
oCookies, oFile, File, oFilesCollection, tCookies, col

Set objShell = CreateObject("Shell.Application") Set objFSO =
CreateObject("Scripting.FileSystemObject")


set sUserDir = objFSO.GetFolder("D:\TEST")
' Get user profile folder
ShowSubFolders objFSO.GetFolder(sUserDir)
' Get Sub Folders

'On Error Resume Next

Sub ShowSubFolders(Col)
On Error Resume Next
For Each SubFolder In Col.SubFolders
If SubFolder.name = "Cookies" Then
Wscript.echo "Deleteing Files From" & Space(2) & SubFolder.Path
Set oFilesCollection = SubFolder.Files
'On Error GoTo 0
'On Error Resume Next
For Each oFile IN oFilesCollection
IF DateDiff("d",oFile.DateLastModified,Now)>7 Then
oFile.Delete(True)
If Err.Number <> 0 Then
WScript.Echo "Can't Delte the file" & Space(2) & oFile.Path
WScript.Echo "(" & Err.Number & ") " & Err.Description
'WScript.Echo ""
WScript.Quit Err.Number
End if
'Wscript.echo oFile.name
Err.clear
End If
next
'On Error GoTo 0
End If
'On Error GoTo 0

ShowSubFolders SubFolder

'Err.clear
Next

'Err.clear
End Sub



Thanks
cha