Error Handling Not Working - Dir$

I have a script that loops through all the filenames in an array and checks to see if they exist, then does some other ‘stuff’. I’m having a problem if a particular folder doesn’t exist. The first time it comes across a folder that doesn’t exist, the error handling works, and it goes to the place I direct it. The second time it comes across a folder that doesn’t exist, agent execution ends with a “Path Not Found” error as if there were no error handling. Here’s the code that is causing the problems. What did I do wrong? How can I change it so the error will be handled each time?

Forall infxFilePath In uInfxFiles

fileExist = “”

On Error Goto pathNotFound

fileExist = Dir$(pathPrefix & infxFilePath) 'error handling is not working. Works first time through. Second time, errors out

If fileExist <> “” Then 'file exists

  'do nothing, this is OK

Else

  'do something else

End If

End Forall

Subject: Error Handling Not Working - Dir$

Hi,

This one is quite interesting!!!

Not many ideas from me really, only thing I would suggest is that when I expect/know a certain error is going to be encountered I accommodate for it by stating the specific error number as below.

On Error 1234 Goto HandleErr

This may prove to be more explicit when catching this error. Please let me know if this has any relevant effect as this intrigues me!!

Regards

Subject: RE: Error Handling Not Working - Dir$

Didn’t work. I tried on error 76 goto pathNotFound.I also tried resetting to 0 each time through the loop.

I put in a msgbox so I can see that err is 0 before it hits the line where it errors out.

This is gonna drive me up the wall!!

Subject: RE: Error Handling Not Working - Dir$

Just out of interest try:

On Error DIR_ERROR GoTo …

Probaly wont make a difference. Out of interest have you got more then one “on Error GoTo…” line of syntax? This could be a cause of a problem as you describe if it was encountering the first(correct handling) then seeing the second ‘On Error…’ command. As the second instruction will overwrite the initial one.

Subject: RE: Error Handling Not Working - Dir$

From Heinz Ulrich Krause,

dummy = ExistFileDirDrive(“FilePath”)

If Not(dummy > 0) Then

Doesn’t exist

else

'Exist

end if

Function ExistFileDirDrive(FilePathName As String) As Integer

Module = Getthreadinfo(1)

Dim nTest As String

nTest = Lcase$(FilePathName)

If Len(nTest) = 1 Then

Select Case Left$(nTest, 1)

Case “a” To “z”

nTest = FilePathName & ":"

End Select

Elseif Len(nTest) = 2 Then

Select Case Left$(nTest, 2)

Case “a:” To “z:”

nTest = FilePathName & ""

End Select

End If

On Error Resume Next

ExistFileDirDrive = Cint(Getattr(nTest) Or vbNormal _

Or vbHidden Or vbSystem Or vbArchive Or vbDirectory)

End Function

Subject: RE: Error Handling Not Working - Dir$

Thanks! I haven’t tried it because I finally got something working (after hours of playing with it)! For some reason it didn’t like the “on error goto pathNotFound” line. Once I removed that line and just left an “on error goto errHand” line at the top of my agent. Then errHand code is:if err = 76 then

'path not found do something

else

'other error - do something else

end if

Works fine. Not sure why it didn’t work the other way, but this is working and actually easier to follow in the case of an error so I’m probably better off.

Thanks for the help!! I really appreciate it!