[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help Me!! Getting CATALOG into an Array Variable
Jon Bettencourt <jonINTERNETrelayCHAT@napaVALLEYnet.CLARInet> wrote:
> I'm trying to get the CATALOG of the current ProDOS directory into an
> array in Applesoft.
The correct technique is to use the OPEN then READ command to open the
directory and start reading from it, then use the INPUT command to read
each line of the catalog. (You need to use the ",TDIR" directive with
the open command, since you aren't opening a text file.)
You always get the 80-column version of the catalog, and there is a
minor difference from how it is displayed: the blank line after the
directory name isn't delivered via the INPUT statement.
You can detect the end of the catalog by a blank line at the end, and
then read one more line to get the disk space line. (You don't need an
ONERR GOTO handler.)
For example, if you have a volume called /APPLEWORKS (as we all probably
do), then the following program should read the catalog into an array.
10 D$=CHR$(4)
20 DIM F$(51)
30 PRINT D$;"OPEN /APPLEWORKS,TDIR"
40 PRINT D$;"READ /APPLEWORKS"
50 INPUT N$: REM Directory name
60 INPUT T$: REM Title line
70 INPUT B$: REM Blank line
80 N = 0
90 INPUT F$: REM One file line
100 IF F$ <> "" THEN N = N + 1: F$(N) = F$: GOTO 90
110 INPUT U$: REM Usage
120 PRINT D$;"CLOSE"
130 REM Insert code to do something useful with it...
140 END
Note that you have to be careful with the array size. 51 is sufficient
for a root directory (assuming a disk which follows the standards), but
there is no limit on the size of a subdirectory.
--
David Empson
dempson@actrix.gen.nz
Snail mail: P O Box 27-103, Wellington, New Zealand