[comp.sys.apple] CATALOG into a file

jerryk@pro-beagle.cts.com (Jerry Kindall) (01/28/89)

Oddly enough, someone recently asked a very similar (if not identical)
question on the Fidonet Apple Echo.  How do you write a ProDOS catalog into a
file?

You would think that the following would work:

10 PRINT CHR$(4);"OPEN CATFILE"
20 PRINT CHR$(4);"WRITE CATFILE"
30 PRINT CHR$(4);"CATALOG"
40 PRINT CHR$(4);"CLOSE CATFILE"

However, this doesn't work.  The problem is that BASIC.SYSTEM turns off write
mode whenever a disk command is executed.  So in line 30, disk writing is
deactivated and the catalog goes to the screen instead of the file.

This MIGHT work:

10 PRINT CHR$(4);"OPEN /DIRECTORY,TDIR"
20 PRINT CHR$(4);"OPEN CATFILE"
30 ONERR GOTO 50
40 GOSUB 100:GOSUB 200:GOTO 40
50 PRINT CHR$(4);"CLOSE"
100 PRINT CHR$(4);"READ /DIRECTORY"
110 INPUT X$:RETURN
200 PRINT CHR$(4);"WRITE CATFILE"
210 PRINT X$:RETURN

Ooops... add a line 60 END to the above listing.  I tried a similar technique
and that, for some odd reason, does not work properly either.

The only strategy I have found that works is to read the entire directory into
an array, then close the directory file and write the text file separately. 
This is a little more involved than the above, but it is still pretty easy.

10 PRINT CHR$(4);"OPEN /DIRECTORY,TDIR"
20 DIM F$(255)
30 PRINT CHR$(4);"READ /DIRECTORY,TDIR"
40 ONERR GOTO 60
50 INPUT F$(N):N=N+1:GOTO 50
60 PRINT CHR$(4);"CLOSE /DIRECTORY"
70 POKE 216,0
80 PRINT CHR$(4);"OPEN CATFILE"
90 PRINT CHR$(4);"WRITE CATFILE"
100 FOR I=0 TO N:PRINT F$(I):NEXT
110 PRINT CHR$(4);"CLOSE"

That should come pretty close to working.  Since I typed all this up off the
top of my head, the programs may have a few errors, but I think they show the
general direction to take.

/\
  \/  Jerry Kindall

UUCP: nosc!crash!pro-beagle!jerryk
Proline: jerryk@pro-beagle
GEnie: J.KINDALL
Alink: JKindall
FrEdMail: JEKind@COLS