Michael <
michael...@gmail.com> wrote:
> Hi Guys,
>
> I have been using OS_File,20 to detect if a file exists without issue
> until I unplugged my USB stick.
>
> Now I get the error 76288 "Could not open filesystem"
>
> Obviously using Basalt (I am using BASIC), I can trap this error, but what
> would be the correct way of detecting this?
You always need to be prepared that a filing system call returns an error
anyway. In this context, it is easy because if all you are interested in is
whether the given file exists, then an error is a very good indicator that
the file does not exist. You could call OS_File and use your programming
language's error handling mechanism to trap the error as you suggested, but
it is cleaner and more efficient to call XOS_File instead and check the
returned V flag. As John has pointed out, to avoid confusion with path
variables, it is best to use the "no paths" variant of the call, i.e.,
reason code 23.
SYS "XOS_File",23,<other parameters> TO <return parameters>;FLG%
IF FLG% AND 1 THEN
FileExists = FALSE
ELSE
check the return parameters to decide whether the file exists
ENDIF
--
Martin Wuerthner MW Software
http://www.mw-software.com/
------- RISC OS Software for Design, Printing and Publishing --------