REM  BigDir <directory>
REM
REM  Make a directory with more entries than one request returns, list it
REM  back and check every one is there.  A directory small enough to arrive
REM  in a single reply proves nothing about the ones that do not, which is
REM  how a walk that stopped part way through went unnoticed.
ON ERROR PRINT "  error ";ERR;" ";REPORT$ : END
n% = 200
SYS "OS_GetEnv" TO cl%
c$ = ""
REPEAT
  ch% = ?cl%
  IF ch% > 31 THEN c$ = c$ + CHR$(ch%)
  cl% = cl% + 1
UNTIL ch% < 32
REM Run on a tokenised program puts "BASIC -quit <prog>" in front, so the
REM directory is whatever the last word is.
w$ = c$
WHILE INSTR(w$, " ") > 0
  w$ = MID$(w$, INSTR(w$, " ") + 1)
ENDWHILE
d$ = w$
PRINT "  making ";n%;" entries in ";d$
SYS "OS_File", 8, d$, 0, 0, 0, 0
FOR i% = 1 TO n%
  f% = OPENOUT(d$ + ".b" + STR$(i%))
  BPUT #f%, i% MOD 256
  CLOSE #f%
NEXT
DIM buf% 16384
off% = 0
total% = 0
calls% = 0
REPEAT
  SYS "OS_GBPB", 9, d$, buf%, 60, off%, 16384, "*" TO ,,,read%,next%
  calls% = calls% + 1
  total% = total% + read%
  off% = next%
UNTIL next% = -1 OR calls% > 60
IF total% = n% THEN PRINT "  ALL ";total%;" listed, in ";calls%;" requests" ELSE PRINT "  WRONG: ";total%;" of ";n%;" listed"
FOR i% = 1 TO n%
  SYS "OS_File", 6, d$ + ".b" + STR$(i%)
NEXT
SYS "OS_File", 6, d$
PRINT "  removed"
