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