[comp.sys.apple] getting CATALOG into text file--tested code + info

AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") (01/29/89)

>Date:         Tue, 24 Jan 89 19:12:00 GMT
>From:         Jerry Bauer <tolerant!procase!bauer@UCBVAX.BERKELEY.EDU>
>Subject:      Getting a CATALOG into a file

>Alright, class, today's question is:
>
>Under ProDOS, in APPLESOFT, how can one get a list of the files on
>a given disk (CATALOG) into a file?

To answer a different question first, if you want to do this in a
utility program rather than from a program of your own, you can do
it in Davex (Shareware, by me) with a command like:

  > whatever; cat /h2

The 'cat' command in Davex is very flexible, letting you sort the
listing in various ways and show the contents of subdirectories.

-------------

Applesoft itself doesn't have any disk-oriented commands.  They are
available under DOS 3.3 and BASIC.SYSTEM by PRINTing a Control-D
(CHR$(4)) followed by a command.  Buying _BASIC Programming with
ProDOS_ from Addison-Wesley (APDA #A7Z0015, $29.95), would be a
fairly intelligent thing to do, because the info you need is in
there, and you'll be able to look it up a lot faster than you'll get
complete responses on the net.  (I'm a busy guy and am not always
inclined to explain things that are already explained well in
readily-available manuals.)

Anyway, the following code has been tested:
50 DIM A$(200)
100 F$ = "whatever"
110 DIR$ = "/h2"
120 D$ = CHR$ (4)
200 PRINT D$;"open ";DIR$;",tDIR"
205 PRINT D$;"read ";DIR$
210 I = I + 1: INPUT "";A$(I)
220 IF LEFT$ (A$(I),6) < > "BLOCKS" THEN 210
300 PRINT D$;"close ";DIR$

310 PRINT D$;"open ";F$
320 PRINT D$;"write ";F$
330 FOR J = 1 TO I
340   PRINT A$(J)
350 NEXT J
360 PRINT D$;"close ";F$

The idea is to read the directory into an array until you come to
the last line, which starts out "BLOCKS FREE:...", and then print
the array back out to a text file.  The size of the array is
arbitrary, and a robust program will check that the array is about
to be overflowed by a large directory rather than letting the
program crash with a ?BAD SUBSCRIPT ERROR.

>JRBauer (Jerry) ...!tolerant!procase!bauer
>                ...!hpda!procase!bauer
>                ...!cae780!procase!bauer

--David A. Lyons              bitnet: awcttypa@uiamvs
  DAL Systems                 CompuServe:  72177,3233
  P.O. Box 287                GEnie mail:    D.LYONS2
  North Liberty, IA 52317     AppleLinkPE: Dave Lyons

reeder@reed.UUCP (Doug Reeder) (02/10/89)

Does anyone know if when reading directory files as if they were text files:

10 ?chr$(4);"OPEN /DISK,TDIR"
20 ?CHR$(4);"READ /DISK"

is the ramdisk ( /RAM ) read properly?  Older versions of ProDOS had trouble
with /RAM, because it was shorter than the standard 4 block directory.
-- 
Doug Reeder                         USENET: ...!tektronix!reed!reeder
Box 971                             BITNET: reeder@reed.BITNET
Imperial University              from ARPA: tektronix!reed!reeder@berkeley.EDU
Trantor                             Box 971 Reed College,Portland,OR 97202