[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: output redirection



William Katz <druid@dorsai.org> wrote:

> I ran your program, and even ran it with lines 70 and 80 swapped, but it
> only captures the first filename from a directory, to the
> "catalog.txt" file, and stops right there.

It turns out that I hit a feature which I didn't know before.  Issuing a
ProDOS READ command on an open directory appears to reset the current
position back to the blank line prior to the first file.  (The behaviour
might be more complicated than this, e.g. it might reset back to the
first file entry in the current block of the directory.)  The blank line
confused the program into thinking it had reached the end of the
directory.

This makes it harder to interleave reading the directory and writing to
another file.  The easiest solution is to DIM the array for the largest
directory you expect to encounter.  Here is a simplified version which
should work for any directory with up to 250 files.

(There was also a limit error in the FOR loop - my mistake.)

10 mf=250: dim l$(mf-1): rem mf = max files in directory
20 d$=chr$(4): f$="/pathname/of/folder": t$="catalog.txt"
30 print d$;"open ";f$;",tdir"
40 print d$;"create ";t$;",ttxt"
50 print d$;"open ";t$
60 print d$;"read ";f$
70 input a$: rem pathname
80 input c$: rem catalog title
90 input b$: rem blank line - discarded
100 n = 0
110 input l$: rem file line
120 if l$ = "" then goto 200: rem no more file lines
130 l$(n) = l$
140 n = n + 1
150 if n < mf then goto 110
160 rem If we get here, there are too many files.  Skip the rest.
190 rem You might want to print an overflow warning here
180 input l$: rem file line
190 if l$ <> "" then goto 180
200 input s$: rem summary line
210 print d$;"write ";t$
220 print a$: print: print c$: print
230 if n = 0 then goto 250
240 for i = 0 to n - 1: print l$(i): next 
250 print: print s$
260 print d$;"close"
270 end

> Can you try it yourself, either on a real Apple II or an Apple II emulator
> program.

I had to use Bernie, as I no longer have a real Apple II set up for
regular use.  It seems to work, but I haven't tested it to the maximum
file limit.