Hello I am processing loose files and have a text-file list of paths. Using the GetFileAttr(path$) it works just fine as I can separate out the directories from the files themselves. Problem - when the code encounters a bad file name I can't trap the error, Notes pops up a "File Not Found" error and the code terminates.
Is there a better way to test string values to see if they are valid files? I have tried putting in an err_handler but Notes simply produces the "File Not Found" error pop-up.
To test the problem you can code a button with the follwing script:
Sub Click
msg$ = Inputbox$("enter a file name", "filename","c:boc.txt")
attr%= Getfileattr(msg$)
Messagebox Str(attr%)
End Sub
Thanks for your help - Mike
Software/Hardware used:
ASKED:
April 24, 2007 8:04 AM
UPDATED:
April 24, 2007 10:58 AM
mHanson,
You could try using the Dir$ function to test the validity of paths and file names. For example,
If Dir$(msg$) “” then
‘process the file
Esle
‘handle your incorrect information
Messagebox “File “”" & msg$ & “”" not found.”
End If
This should be placed before your call to GetFileAttr.
Also, why didn’t trapping Err = 5 (File Not Found) work?
Charles
Stilleto: Agreed. mHanson should be able to put in a generic error handler and this line to find out the error number,
Messagebox “Error” & Str(Err) & “: ” & Error$
…then code a specific action to occur when that number is encountered. In my example below, error 75 is returned if I try to access a folder that does not exist and my code creates the new folder (I actually can’t remember exactly how it does it, but I know it works).
Example:
On Error Goto Errhandle
….code here
Exit Sub
Errhandle:
‘ Use the Err function to return the error number and
‘ the Error$ function to return the error message.
If Err = 75 Then
Resume Next
Else
Messagebox “Error” & Str(Err) & “: ” & Error$
Exit Sub
End If
End Sub
CharlesJC, I think you may have miskeyed. I think the error number is 53. AKA ErrFileNotFound if using lserr.lss