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

File not found (error 53)

3 views
Skip to first unread message

who where

unread,
Nov 19, 2009, 8:13:10 AM11/19/09
to
As part of a much larger program, I have a routine which parses a
large file looking for a certain byte sequence. If the file does not
exist, an alternate process is followed. Sounds straightforward.

I had anticipated that an error 53 ("file not found") would be
triggered by an attempt to open the target file if it didn't already
exist. But "Details" for OPEN states "if file$ does not exist, it
will be created". So my attempt to use error trapping to drive the
decision process fails.

While I can work around this by another means, is there actually a way
that an ERR53 can arise without fudging it? That woudl set me on a
better path and avoid the need to delete the null file that is
created.

Karl E. Peterson

unread,
Nov 19, 2009, 1:49:45 PM11/19/09
to

The "classic" approach would be to test whether the file exists, before attempting
to open it, if you don't want to create a new file when it doesn't. What language
are you using?
--
.NET: It's About Trust!
http://vfred.mvps.org


ArarghMai...@not.at.arargh.com

unread,
Nov 19, 2009, 3:51:29 PM11/19/09
to

Maybe:
IF DIR$("filename") = "" the file does not exist.
--
ArarghMail911 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

who where

unread,
Nov 20, 2009, 7:07:05 AM11/20/09
to
On Thu, 19 Nov 2009 14:51:29 -0600,
ArarghMai...@NOT.AT.Arargh.com wrote:

>On Thu, 19 Nov 2009 21:13:10 +0800, who where <no...@home.net> wrote:
>
>>As part of a much larger program, I have a routine which parses a
>>large file looking for a certain byte sequence. If the file does not
>>exist, an alternate process is followed. Sounds straightforward.
>>
>>I had anticipated that an error 53 ("file not found") would be
>>triggered by an attempt to open the target file if it didn't already
>>exist. But "Details" for OPEN states "if file$ does not exist, it
>>will be created". So my attempt to use error trapping to drive the
>>decision process fails.
>>
>>While I can work around this by another means, is there actually a way
>>that an ERR53 can arise without fudging it? That woudl set me on a
>>better path and avoid the need to delete the null file that is
>>created.
>
>Maybe:
> IF DIR$("filename") = "" the file does not exist.

Yes, I appreciate there are a number of ways to ascertain whether the
file exists. I was tossed a little by VB-DOS' behaviour in creating
the file rather than returning the error which seems made for this
eventuality.

The real question though is as above - is there a way that an ERR53
can arise?

who where

unread,
Nov 20, 2009, 7:07:13 AM11/20/09
to
On Thu, 19 Nov 2009 10:49:45 -0800, "Karl E. Peterson"
<ka...@exmvps.org> wrote:

>The "classic" approach would be to test whether the file exists, before attempting
>to open it, if you don't want to create a new file when it doesn't. What language
>are you using?

The group name doesn't give you the answer?

ArarghMai...@not.at.arargh.com

unread,
Nov 20, 2009, 8:28:19 AM11/20/09
to
On Fri, 20 Nov 2009 20:07:05 +0800, who where <no...@home.net> wrote:

>On Thu, 19 Nov 2009 14:51:29 -0600,
>ArarghMai...@NOT.AT.Arargh.com wrote:
>
>>On Thu, 19 Nov 2009 21:13:10 +0800, who where <no...@home.net> wrote:
>>
>>>As part of a much larger program, I have a routine which parses a
>>>large file looking for a certain byte sequence. If the file does not
>>>exist, an alternate process is followed. Sounds straightforward.
>>>
>>>I had anticipated that an error 53 ("file not found") would be
>>>triggered by an attempt to open the target file if it didn't already
>>>exist. But "Details" for OPEN states "if file$ does not exist, it
>>>will be created". So my attempt to use error trapping to drive the
>>>decision process fails.

Quote from the VB docs:
"If the file specified by pathname doesn't exist, it is created when a
file is opened for Append, Binary, Output, or Random modes."

Try opening for INPUT.
If it doesn't work, you should get the error you wnat.
If it works, close it and reopen however it was that created the file.

>>>While I can work around this by another means, is there actually a way
>>>that an ERR53 can arise without fudging it? That woudl set me on a
>>>better path and avoid the need to delete the null file that is
>>>created.
>>
>>Maybe:
>> IF DIR$("filename") = "" the file does not exist.
>
>Yes, I appreciate there are a number of ways to ascertain whether the
>file exists. I was tossed a little by VB-DOS' behaviour in creating
>the file rather than returning the error which seems made for this
>eventuality.
>
>The real question though is as above - is there a way that an ERR53
>can arise?

IF DIR$("filename") = "" then error 53

Assumming vb has an error statement.

H-Man

unread,
Nov 20, 2009, 10:07:38 AM11/20/09
to
On Fri, 20 Nov 2009 07:28:19 -0600, ArarghMai...@NOT.AT.Arargh.com wrote: > On Fri, 20 Nov 2009 20:07:05 +0800, who where <no...@home.net> wrote: >>On Thu, 19 Nov 2009 14:51:29 -0600, >>ArarghMai...@NOT.AT.Arargh.com wrote: >>>On Thu, 19 Nov 2009 21:13:10 +0800, who where <no...@home.net> wrote: >>>>As part of a much larger program, I have a routine which parses a >>>>large file looking for a certain byte sequence. If the file does not >>>>exist, an alternate process is followed. Sounds straightforward. >>>> >>>>I had anticipated that an error 53 ("file not found") would be >>>>triggered by an attempt to open the target file if it didn't already >>>>exist. But "Details" for OPEN states "if file$ does not exist, it >>>>will be created". So my attempt to use error trapping to drive the >>>>decision process fails. > Quote from the VB docs: > "If the file specified by pathname doesn't exist, it is created when a > file is opened for Append, Binary, Output, or Random modes." > Try opening for INPUT. > If it doesn't work, you should get the error you wnat. > If it works, close it and reopen however it was that created the file. >>>>While I can work around this by another means, is there actually a way >>>>that an ERR53 can arise without fudging it? That woudl set me on a >>>>better path and avoid the need to delete the null file that is >>>>created. >>>Maybe: >>> IF DIR$("filename") = "" the file does not exist. >>Yes, I appreciate there are a number of ways to ascertain whether the >>file exists. I was tossed a little by VB-DOS' behaviour in creating >>the file rather than returning the error which seems made for this >>eventuality. >>The real question though is as above - is there a way that an ERR53 >>can arise? > IF DIR$("filename") = "" then error 53 > Assumming vb has an error statement. from the VB-DOS help screen Simulates the occurrence of a Visual Basic error or a user-defined error. ERROR expression% expression% Error code of a Visual Basic or user-defined error; a value between 1 and 32,767, inclusive See Also ERROR$ Function Error/Event Trapping Summary Run-Time Error Codes

ArarghMai...@not.at.arargh.com

unread,
Nov 20, 2009, 12:50:15 PM11/20/09
to

arargh! I knew VBDOS had it, after all it is just an upgraded version
of PDS. Somehow, I was thinking of the gooey version of VB, not the
DOS version.

who where

unread,
Nov 21, 2009, 6:31:50 AM11/21/09
to
On Fri, 20 Nov 2009 07:28:19 -0600,
ArarghMai...@NOT.AT.Arargh.com wrote:

>On Fri, 20 Nov 2009 20:07:05 +0800, who where <no...@home.net> wrote:
>
>>On Thu, 19 Nov 2009 14:51:29 -0600,
>>ArarghMai...@NOT.AT.Arargh.com wrote:
>>
>>>On Thu, 19 Nov 2009 21:13:10 +0800, who where <no...@home.net> wrote:
>>>
>>>>As part of a much larger program, I have a routine which parses a
>>>>large file looking for a certain byte sequence. If the file does not
>>>>exist, an alternate process is followed. Sounds straightforward.
>>>>
>>>>I had anticipated that an error 53 ("file not found") would be
>>>>triggered by an attempt to open the target file if it didn't already
>>>>exist. But "Details" for OPEN states "if file$ does not exist, it
>>>>will be created". So my attempt to use error trapping to drive the
>>>>decision process fails.
>
>Quote from the VB docs:
>"If the file specified by pathname doesn't exist, it is created when a
>file is opened for Append, Binary, Output, or Random modes."

Which doc(s)? In the VB-DOS Reference manual it uses the same wording
as I gave above (from the on-line help), no mention of MODE
differences. Maybe somewhere in the Programmer's Guide? Or are you
looking at the Pro docs?

>Try opening for INPUT.
>If it doesn't work, you should get the error you wnat.
>If it works, close it and reopen however it was that created the file.
>
>>>>While I can work around this by another means, is there actually a way
>>>>that an ERR53 can arise without fudging it? That woudl set me on a
>>>>better path and avoid the need to delete the null file that is
>>>>created.
>>>
>>>Maybe:
>>> IF DIR$("filename") = "" the file does not exist.

yes, using DIR$(Filename$) is the simplest.

>>Yes, I appreciate there are a number of ways to ascertain whether the
>>file exists. I was tossed a little by VB-DOS' behaviour in creating
>>the file rather than returning the error which seems made for this
>>eventuality.
>>
>>The real question though is as above - is there a way that an ERR53
>>can arise?
>IF DIR$("filename") = "" then error 53
>
>Assumming vb has an error statement.

It does.

ArarghMai...@not.at.arargh.com

unread,
Nov 21, 2009, 9:26:10 AM11/21/09
to
On Sat, 21 Nov 2009 19:31:50 +0800, who where <no...@home.net> wrote:

>On Fri, 20 Nov 2009 07:28:19 -0600,
>ArarghMai...@NOT.AT.Arargh.com wrote:
>
>>On Fri, 20 Nov 2009 20:07:05 +0800, who where <no...@home.net> wrote:
>>
>>>On Thu, 19 Nov 2009 14:51:29 -0600,
>>>ArarghMai...@NOT.AT.Arargh.com wrote:
>>>
>>>>On Thu, 19 Nov 2009 21:13:10 +0800, who where <no...@home.net> wrote:
>>>>
>>>>>As part of a much larger program, I have a routine which parses a
>>>>>large file looking for a certain byte sequence. If the file does not
>>>>>exist, an alternate process is followed. Sounds straightforward.
>>>>>
>>>>>I had anticipated that an error 53 ("file not found") would be
>>>>>triggered by an attempt to open the target file if it didn't already
>>>>>exist. But "Details" for OPEN states "if file$ does not exist, it
>>>>>will be created". So my attempt to use error trapping to drive the
>>>>>decision process fails.
>>
>>Quote from the VB docs:
>>"If the file specified by pathname doesn't exist, it is created when a
>>file is opened for Append, Binary, Output, or Random modes."
>
>Which doc(s)? In the VB-DOS Reference manual it uses the same wording

VB6. However, if you attempt to open a non-existant file for input in
VBDOS, you do get the error.

Or, at least, when I just tried it, I did.

>as I gave above (from the on-line help), no mention of MODE
>differences. Maybe somewhere in the Programmer's Guide? Or are you
>looking at the Pro docs?

So, the online docs are wrong / incomplete. Not the first time. :-)


>>Try opening for INPUT.
>>If it doesn't work, you should get the error you wnat.
>>If it works, close it and reopen however it was that created the file.

^ This is still the cleanest way, IMO. ^

OTOH, a LONG time ago I wrote an 'EXIST' function. As in:

IF NOT EXIST("filename") THEN <file ain't there>
IF EXIST("filename") THEN <file is there>

It's an assembler routine that uses FindFirstFile, the same as
DIR$("") does.

>>
>>>>>While I can work around this by another means, is there actually a way
>>>>>that an ERR53 can arise without fudging it? That woudl set me on a
>>>>>better path and avoid the need to delete the null file that is
>>>>>created.
>>>>
>>>>Maybe:
>>>> IF DIR$("filename") = "" the file does not exist.
>
>yes, using DIR$(Filename$) is the simplest.
>
>>>Yes, I appreciate there are a number of ways to ascertain whether the
>>>file exists. I was tossed a little by VB-DOS' behaviour in creating
>>>the file rather than returning the error which seems made for this
>>>eventuality.
>>>
>>>The real question though is as above - is there a way that an ERR53
>>>can arise?
>>IF DIR$("filename") = "" then error 53
>>
>>Assumming vb has an error statement.
>
>It does.

0 new messages