Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting if a file exists

36 views
Skip to first unread message

Michael

unread,
Mar 26, 2013, 8:20:06 PM3/26/13
to
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?

One potential solution I can think of is enumerating the filesystems
and cross checking, however it seems a little OTT?

Cheers
Michael

John Williams (News)

unread,
Mar 27, 2013, 4:01:25 AM3/27/13
to
In article
<418dd2c5-74a0-46af...@k1g2000yqf.googlegroups.com>,
Michael <michael...@gmail.com> wrote:

> 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"

I've always used OS_File,23 for this where one specifies the complete path
rather than use File$Path as with OS_File,20.

Could this be the problem?

John

--
John Williams, Brittany, Northern France - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/

Martin Bazley

unread,
Mar 27, 2013, 7:39:46 AM3/27/13
to
The following bytes were arranged on 27 Mar 2013 by Michael :

> 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?

...Don't unplug the USB stick?

--
__<^>__ Red sky in the morning: Shepherd's warning
/ _ _ \ Red sky at night: Shepherd's delight
( ( |_| ) ) Mince and potatoes: Shepherd's pie
\_> <_/ ======================= Martin Bazley ==========================

Martin Wuerthner

unread,
Mar 27, 2013, 10:44:24 AM3/27/13
to
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 --------

jgharston

unread,
Mar 28, 2013, 8:38:20 PM3/28/13
to
Martin Wuerthner wrote:
> 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

I tend to use OS_File 17 "Read catalogue information with no path"

SYS "XOS_File",17,filename$ TO object%;flag%
IF (flag% AND 1) THEN object%=0
IF object%=0 THEN object does not exist

JGH
0 new messages