A
adrianr
Guest
Hello,
I hope this is the correct group to send this to....
I've written a vbscript that searches through a file system and reports on
files that have not been accessed in xx days. I pulled a lot of the code
from scripting guys examples.
My scripts works fine until I get to a folder that the script does not have
access to. With 'On Error Resume Next' configured, I check to see if 'err'
is <> 0 and if so, write the problem folder to a dictonary object before
clearing the error and then resuming the script.
My problem is that for some unknown reason, my script always picks up the
next folder in the sequence and reports an error on that too - even if it
gets processed.
Can someone point out what I'm doing wrong?
I've put a snippet of the code at the bottom - I can post the whole thing if
requested.
Many Thanks,
Adrian
My Subroutine that gets called:
Sub ShowSubFolders(Folder)
On Error Resume Next
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
' For Each file in the folder....
For Each objFile in colFiles
dtmFileDate = objFile.DateLastAccessed
If dtmFileDate < dtmDate Then
strText = objFile.Path
fleLOG.WriteLine strText
End If
Next
If Err <> 0 Then
'We have an error reading the files/folders - probably access
denied...
strText = SubFolder.Path
If Not objDictionary.Exists(strText) Then
objDictionary.Add strText, strText
intErrorCount = intErrorCount + 1
wscript.echo "Error Number : " & intErrorCount & " is with :
" & strText & " and error code is " & err.description
Err.Clear
End If
End If
' Routine calls itself recusively until the folder tree is processed.
ShowSubFolders Subfolder
Next
End Sub
My bit at the end that logs 'problem' folders:
If intErrorCount > 0 Then
wscript.echo intErrorCount
Set fleErr = objFSO.CreateTextFile(strErrorFile, TRUE)
For Each strText in objDictionary.Keys
fleErr.WriteLine strText
Next
End If
I have one folder that I can't access - however intErrorCount is always 3
and two folders are in my errors.txt file:
C:\System Volume Information
C:\System Tests
I hope this is the correct group to send this to....
I've written a vbscript that searches through a file system and reports on
files that have not been accessed in xx days. I pulled a lot of the code
from scripting guys examples.
My scripts works fine until I get to a folder that the script does not have
access to. With 'On Error Resume Next' configured, I check to see if 'err'
is <> 0 and if so, write the problem folder to a dictonary object before
clearing the error and then resuming the script.
My problem is that for some unknown reason, my script always picks up the
next folder in the sequence and reports an error on that too - even if it
gets processed.
Can someone point out what I'm doing wrong?
I've put a snippet of the code at the bottom - I can post the whole thing if
requested.
Many Thanks,
Adrian
My Subroutine that gets called:
Sub ShowSubFolders(Folder)
On Error Resume Next
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
' For Each file in the folder....
For Each objFile in colFiles
dtmFileDate = objFile.DateLastAccessed
If dtmFileDate < dtmDate Then
strText = objFile.Path
fleLOG.WriteLine strText
End If
Next
If Err <> 0 Then
'We have an error reading the files/folders - probably access
denied...
strText = SubFolder.Path
If Not objDictionary.Exists(strText) Then
objDictionary.Add strText, strText
intErrorCount = intErrorCount + 1
wscript.echo "Error Number : " & intErrorCount & " is with :
" & strText & " and error code is " & err.description
Err.Clear
End If
End If
' Routine calls itself recusively until the folder tree is processed.
ShowSubFolders Subfolder
Next
End Sub
My bit at the end that logs 'problem' folders:
If intErrorCount > 0 Then
wscript.echo intErrorCount
Set fleErr = objFSO.CreateTextFile(strErrorFile, TRUE)
For Each strText in objDictionary.Keys
fleErr.WriteLine strText
Next
End If
I have one folder that I can't access - however intErrorCount is always 3
and two folders are in my errors.txt file:
C:\System Volume Information
C:\System Tests