d_melnyk
asked on
Continuing a "For Each" loop when error occurs in "For " statement
Hi Folks:
I am programming a recursive function to load a database table with all directories and files given a specific starting path. The code works, but hits a snag when I hit the "System Volume Information directory which is access denied. on a drive the line throwing the exception is the
"For each fileObject in dirinfo.getfilesysteminfos ()" which starts the loop. A try catch around the loop will catch the error, but then any other items in the collection will not be processed as I am now "out" of the for each / next loop. How can I recover from the error being generated on that line - just need to write and error message to a log file and then continue the For Each / next until all items are done.
Any assistance will be greatly appreciated.
Best regards, Dave Melnyk
I am programming a recursive function to load a database table with all directories and files given a specific starting path. The code works, but hits a snag when I hit the "System Volume Information directory which is access denied. on a drive the line throwing the exception is the
"For each fileObject in dirinfo.getfilesysteminfos
Any assistance will be greatly appreciated.
Best regards, Dave Melnyk
Dim fileobject as FileSystemInfo
Dim dirInfo As New IO.DirectoryInfo(Resource & Folder)
For Each fileobject In dirInfo.GetFileSystemInfos()
' process directories and files here ...
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi VBRocks ...
Oops ... seemed I made a bit of a mistake setting up the catch - appears your solution is correct and will catch that error - seems strange though as the "try / catch" is within the loop and one would think that it would only catch errors in the code it encapsulates, not from the line above - seems strange ... but at least problem seems solved. Thanks again..
Oops ... seemed I made a bit of a mistake setting up the catch - appears your solution is correct and will catch that error - seems strange though as the "try / catch" is within the loop and one would think that it would only catch errors in the code it encapsulates, not from the line above - seems strange ... but at least problem seems solved. Thanks again..
ASKER
regards, Dave Melnyk