Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » How to check for file's existence on a C64 disk?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to check for file's existence on a C64 disk? [message #208469] Wed, 27 April 2011 12:55 Go to next message
Brandon Taylor is currently offline  Brandon Taylor
Messages: 144
Registered: April 2012
Karma: 0
Senior Member
Does anyone know what command one would issue, or what program one
would run, if one simply wants to verify that a file exists on a C64
disk? The nearest I could find is this program:

10 REM
20 OPEN 1, 8, 4, "TESTFILE, SEQ, W"
30 IF ST <> 0 THEN PRINT "FILE ERROR"
40 IF ST = 0 THEN PRINT "FILE EXISTS"
50 CLOSE 1
(courtesy c64-wiki.com)

but, whether TESTFILE exists or not, ST (short for STATUS) always
comes back 0, and the C64 always returns "FILE EXISTS" -- unless, of
course, there is no disk in my drive, at which point ST would NOT be
0, and the C64 would then say "FILE ERROR". The difference is, if
TESTFILE did exist before line 20, I would get a drive error,
signified by the flashing drive light; but if not, the C64 would
simply create a file called "TESTFILE".

While this is a simple yet functional BASIC program, it does not
really do me much good as far as checking for the existence of a file.
So, does anyone know a better command or program?

Thank you.

Brandon Taylor
Re: How to check for file's existence on a C64 disk? [message #208470 is a reply to message #208469] Wed, 27 April 2011 13:22 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Fred Winter

On 04/27/2011 11:55 AM, DMn2004404 wrote:
> Does anyone know what command one would issue, or what program one
> would run, if one simply wants to verify that a file exists on a C64
> disk? The nearest I could find is this program:
>
> 10 REM
> 20 OPEN 1, 8, 4, "TESTFILE, SEQ, W"
> 30 IF ST<> 0 THEN PRINT "FILE ERROR"
> 40 IF ST = 0 THEN PRINT "FILE EXISTS"
> 50 CLOSE 1
> (courtesy c64-wiki.com)
>
> but, whether TESTFILE exists or not, ST (short for STATUS) always
> comes back 0, and the C64 always returns "FILE EXISTS" -- unless, of
> course, there is no disk in my drive, at which point ST would NOT be
> 0, and the C64 would then say "FILE ERROR". The difference is, if
> TESTFILE did exist before line 20, I would get a drive error,
> signified by the flashing drive light; but if not, the C64 would
> simply create a file called "TESTFILE".
>
> While this is a simple yet functional BASIC program, it does not
> really do me much good as far as checking for the existence of a file.
> So, does anyone know a better command or program?
>
> Thank you.
>
> Brandon Taylor

Open for Reading instead of Writing?
Re: How to check for file's existence on a C64 disk? [message #208471 is a reply to message #208470] Wed, 27 April 2011 13:50 Go to previous messageGo to next message
Brandon Taylor is currently offline  Brandon Taylor
Messages: 144
Registered: April 2012
Karma: 0
Senior Member
On Apr 27, 12:22 pm, Fred Winter <retni...@gmail.com> wrote:
> On 04/27/2011 11:55 AM, DMn2004404 wrote:
>
>
>
>
>
>
>
>
>
>> Does anyone know what command one would issue, or what program one
>> would run, if one simply wants to verify that a file exists on a C64
>> disk? The nearest I could find is this program:
>
>> 10 REM
>> 20 OPEN 1, 8, 4, "TESTFILE, SEQ, W"
>> 30 IF ST<>  0 THEN PRINT "FILE ERROR"
>> 40 IF ST = 0 THEN PRINT "FILE EXISTS"
>> 50 CLOSE 1
>> (courtesy c64-wiki.com)
>
>> but, whether TESTFILE exists or not, ST (short for STATUS) always
>> comes back 0, and the C64 always returns "FILE EXISTS" -- unless, of
>> course, there is no disk in my drive, at which point ST would NOT be
>> 0, and the C64 would then say "FILE ERROR". The difference is, if
>> TESTFILE did exist before line 20, I would get a drive error,
>> signified by the flashing drive light; but if not, the C64 would
>> simply create a file called "TESTFILE".
>
>> While this is a simple yet functional BASIC program, it does not
>> really do me much good as far as checking for the existence of a file.
>> So, does anyone know a better command or program?
>
>> Thank you.
>
>> Brandon Taylor
>
> Open for Reading instead of Writing?

That has absolutely no effect -- again, the Commodore 64 always says
"FILE EXISTS."
Re: How to check for file's existence on a C64 disk? [message #208472 is a reply to message #208471] Wed, 27 April 2011 16:11 Go to previous messageGo to next message
JB is currently offline  JB
Messages: 42
Registered: January 2013
Karma: 0
Member
On Apr 27, 1:50 pm, DMn2004404 <dmn2004...@gmail.com> wrote:
> On Apr 27, 12:22 pm, Fred Winter <retni...@gmail.com> wrote:
>
>
>
>> On 04/27/2011 11:55 AM, DMn2004404 wrote:
>
>>> Does anyone know what command one would issue, or what program one
>>> would run, if one simply wants to verify that a file exists on a C64
>>> disk? The nearest I could find is this program:
>
>>> 10 REM
>>> 20 OPEN 1, 8, 4, "TESTFILE, SEQ, W"
>>> 30 IF ST<>  0 THEN PRINT "FILE ERROR"
>>> 40 IF ST = 0 THEN PRINT "FILE EXISTS"
>>> 50 CLOSE 1
>>> (courtesy c64-wiki.com)
>
>>> but, whether TESTFILE exists or not, ST (short for STATUS) always
>>> comes back 0, and the C64 always returns "FILE EXISTS" -- unless, of
>>> course, there is no disk in my drive, at which point ST would NOT be
>>> 0, and the C64 would then say "FILE ERROR". The difference is, if
>>> TESTFILE did exist before line 20, I would get a drive error,
>>> signified by the flashing drive light; but if not, the C64 would
>>> simply create a file called "TESTFILE".
>
>>> While this is a simple yet functional BASIC program, it does not
>>> really do me much good as far as checking for the existence of a file..
>>> So, does anyone know a better command or program?
>
>>> Thank you.
>
>>> Brandon Taylor
>
>> Open for Reading instead of Writing?
>
> That has absolutely no effect -- again, the Commodore 64 always says
> "FILE EXISTS."

Open the file for reading and check the command channel (open 15,8,15
and then input #15,e,em$) if e = 0 then the file exists

Hope that helps
Re: How to check for file's existence on a C64 disk? [message #208476 is a reply to message #208472] Thu, 28 April 2011 10:57 Go to previous messageGo to next message
Brandon Taylor is currently offline  Brandon Taylor
Messages: 144
Registered: April 2012
Karma: 0
Senior Member
On Apr 27, 3:11 pm, JB <jbrown1...@gmail.com> wrote:
> On Apr 27, 1:50 pm, DMn2004404 <dmn2004...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Apr 27, 12:22 pm, Fred Winter <retni...@gmail.com> wrote:
>
>>> On 04/27/2011 11:55 AM, DMn2004404 wrote:
>
>>>> Does anyone know what command one would issue, or what program one
>>>> would run, if one simply wants to verify that a file exists on a C64
>>>> disk? The nearest I could find is this program:
>
>>>> 10 REM
>>>> 20 OPEN 1, 8, 4, "TESTFILE, SEQ, W"
>>>> 30 IF ST<>  0 THEN PRINT "FILE ERROR"
>>>> 40 IF ST = 0 THEN PRINT "FILE EXISTS"
>>>> 50 CLOSE 1
>>>> (courtesy c64-wiki.com)
>
>>>> but, whether TESTFILE exists or not, ST (short for STATUS) always
>>>> comes back 0, and the C64 always returns "FILE EXISTS" -- unless, of
>>>> course, there is no disk in my drive, at which point ST would NOT be
>>>> 0, and the C64 would then say "FILE ERROR". The difference is, if
>>>> TESTFILE did exist before line 20, I would get a drive error,
>>>> signified by the flashing drive light; but if not, the C64 would
>>>> simply create a file called "TESTFILE".
>
>>>> While this is a simple yet functional BASIC program, it does not
>>>> really do me much good as far as checking for the existence of a file.
>>>> So, does anyone know a better command or program?
>
>>>> Thank you.
>
>>>> Brandon Taylor
>
>>> Open for Reading instead of Writing?
>
>> That has absolutely no effect -- again, the Commodore 64 always says
>> "FILE EXISTS."
>
> Open the file for reading and check the command channel  (open 15,8,15
> and then input #15,e,em$)  if e = 0 then the file exists
>
> Hope that helps

I'm confused. I tried this program:

10 OPEN 1,8,4,"TESTFILE,S,R"
20 INPUT#1,E,EM$
30 CLOSE 1
40 PRINT E

and the Commodore 64 returned an E value of 0, which actually is an
assumed value, given the fact that TESTFILE did not exist and
therefore had no numeric value to assign to E. You mentioned checking
the command channel (OPEN 2,8,15), but what drive command would I have
to give to the Commodore 64 before issuing "INPUT#1,E,EM$"?
Re: How to check for file's existence on a C64 disk? [message #208477 is a reply to message #208476] Thu, 28 April 2011 12:07 Go to previous messageGo to next message
Linards Ticmanis is currently offline  Linards Ticmanis
Messages: 253
Registered: April 2012
Karma: 0
Senior Member
On 04/28/2011 04:57 PM, DMn2004404 wrote:

> I'm confused. I tried this program:
>
> 10 OPEN 1,8,4,"TESTFILE,S,R"
> 20 INPUT#1,E,EM$
> 30 CLOSE 1
> 40 PRINT E
>
> and the Commodore 64 returned an E value of 0, which actually is an
> assumed value, given the fact that TESTFILE did not exist and
> therefore had no numeric value to assign to E. You mentioned checking
> the command channel (OPEN 2,8,15), but what drive command would I have
> to give to the Commodore 64 before issuing "INPUT#1,E,EM$"?

Dude, read the command channel, not the file. OPEN 15,8,15, then input
from that - INPUT#15,ER$,EM$,TR$,SC$ or something like that. Don't input
from your file (INPUT#1) but from the command channel(INPUT#15). The
command channel is also a status channel, you don't have to send any
commands to it at all if you only want to use it for error checking.
Getting it?

--
Linards Ticmanis
Re: How to check for file's existence on a C64 disk? [message #208479 is a reply to message #208477] Thu, 28 April 2011 16:02 Go to previous messageGo to next message
Brandon Taylor is currently offline  Brandon Taylor
Messages: 144
Registered: April 2012
Karma: 0
Senior Member
On Apr 28, 11:07 am, Linards Ticmanis <ticma...@gmx.de> wrote:
> On 04/28/2011 04:57 PM, DMn2004404 wrote:
>
>> I'm confused. I tried this program:
>
>> 10 OPEN 1,8,4,"TESTFILE,S,R"
>> 20 INPUT#1,E,EM$
>> 30 CLOSE 1
>> 40 PRINT E
>
>> and the Commodore 64 returned an E value of 0, which actually is an
>> assumed value, given the fact that TESTFILE did not exist and
>> therefore had no numeric value to assign to E. You mentioned checking
>> the command channel (OPEN 2,8,15), but what drive command would I have
>> to give to the Commodore 64 before issuing "INPUT#1,E,EM$"?
>
> Dude, read the command channel, not the file. OPEN 15,8,15, then input
> from that - INPUT#15,ER$,EM$,TR$,SC$ or something like that. Don't input
> from your file (INPUT#1) but from the command channel(INPUT#15). The
> command channel is also a status channel, you don't have to send any
> commands to it at all if you only want to use it for error checking.
> Getting it?
>
> --
> Linards Ticmanis

I think I got it, finally. My program should be:

10 OPEN 1,8,4,"TESTFILE,S,R"
20 OPEN 15,8,15
30 INPUT#15,E,EM$
40 CLOSE 15
50 PRINT E
60 CLOSE 1

using two OPEN commands to open two logical files on the Commodore 64.
Without TESTFILE, the Commodore 64 says E (error code) is 62, which
translates into "FILE NOT FOUND", which I got by telling the Commodore
64 to PRINT EM$. Then, when I saved this test program to disk, I
created a new test program that effectively created an empty TESTFILE.
Finally, upon re-loading and re-running the above test program, the
Commodore 64 said E was 0, and PRINT EM$ returned "OK".

Thanks, guys! I think I finally got it!
Re: How to check for file's existence on a C64 disk? [message #208480 is a reply to message #208479] Thu, 28 April 2011 20:15 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Pinacolada

On Apr 28, 1:02 pm, DMn2004404 <dmn2004...@gmail.com> wrote:
> Thanks, guys! I think I finally got it!

You might want to try something like the following. Replace {filename}
with the file you're checking for, naturally.

1 open 15,8,15
2 print#15,"r0:{filename}={filename}"
3 input#15,e,e$,t,s
4 if e=62 then print "file does not exist"
5 if e=63 then print "file already exists"
6 close 15
Re: How to check for file's existence on a C64 disk? [message #208482 is a reply to message #208480] Fri, 29 April 2011 18:50 Go to previous messageGo to next message
Linards Ticmanis is currently offline  Linards Ticmanis
Messages: 253
Registered: April 2012
Karma: 0
Senior Member
On 04/29/2011 02:15 AM, Pinacolada wrote:

> You might want to try something like the following. Replace {filename}
> with the file you're checking for, naturally.
>
> 1 open 15,8,15
> 2 print#15,"r0:{filename}={filename}"
> 3 input#15,e,e$,t,s
> 4 if e=62 then print "file does not exist"
> 5 if e=63 then print "file already exists"
> 6 close 15

Does that work on write protected disks?

--
Linards Ticmanis
Re: How to check for file's existence on a C64 disk? [message #208483 is a reply to message #208482] Fri, 29 April 2011 19:17 Go to previous messageGo to next message
Bill Garber is currently offline  Bill Garber
Messages: 507
Registered: December 2011
Karma: 0
Senior Member
"Linards Ticmanis" <ticmanis@gmx.de> wrote in message
news:4dbb40ae$0$7664$9b4e6d93@newsspool1.arcor-online.net...
> On 04/29/2011 02:15 AM, Pinacolada wrote:
>
>> You might want to try something like the following. Replace
>> {filename} with the file you're checking for, naturally.
>>
>> 1 open 15,8,15
>> 2 print#15,"r0:{filename}={filename}"
>> 3 input#15,e,e$,t,s
>> 4 if e=62 then print "file does not exist"
>> 5 if e=63 then print "file already exists"
>> 6 close 15
>
> Does that work on write protected disks?
> --
> Linards Ticmanis

I would guess, yes, as long as you open the file for 'read'.

Naturally, you'll get a write-protect error if you open the
file for 'write'. ;)

Bill
Re: How to check for file's existence on a C64 disk? [message #208484 is a reply to message #208482] Fri, 29 April 2011 19:49 Go to previous messageGo to next message
rusure is currently offline  rusure
Messages: 1030
Registered: March 2012
Karma: 0
Senior Member
On Apr 29, 4:50 pm, Linards Ticmanis <ticma...@gmx.de> wrote:
> On 04/29/2011 02:15 AM, Pinacolada wrote:
>
>> You might want to try something like the following. Replace {filename}
>> with the file you're checking for, naturally.
>
>> 1 open 15,8,15
>> 2 print#15,"r0:{filename}={filename}"
>> 3 input#15,e,e$,t,s
>> 4 if e=62 then print "file does not exist"
>> 5 if e=63 then print "file already exists"
>> 6 close 15
>
> Does that work on write protected disks?
I tried this on both a CMD 1581 hard drive partition as well as areal
1581. In addition, the file on the 1581 was locked. In al cases, the
procedure worked as advertised. Remarkable
Re: How to check for file's existence on a C64 disk? [message #208500 is a reply to message #208484] Mon, 02 May 2011 19:58 Go to previous message
Anonymous
Karma:
Originally posted by: @aol.com]Donatello [TMNT]

>
>> You might want to try something like the following. Replace {filename}
>> with the file you're checking for, naturally.
>
>> 1 open 15,8,15
>> 2 print#15,"r0:{filename}={filename}"
>> 3 input#15,e,e$,t,s
>> 4 if e=62 then print "file does not exist"
>> 5 if e=63 then print "file already exists"
>> 6 close 15
>

The LOADSTAR programmer's guidelines suggested that the file be renamed and
the error
channel checked to determine the existence of the specified file, so the
above will work.

> Does that work on write protected disks?

I'm not sure any more, but I wouldn't think so. I haven't touched my
Commodores in over
ten years, so there's much I've forgotten.

Gary Noakes
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: About WELCOME TO THE WORLD OF FRIENDLY COMPUTING
Next Topic: Please vote in Poll on Facebook
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Apr 20 01:21:48 EDT 2024

Total time taken to generate the page: 0.04240 seconds