💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › Mirrors › uni-kl › do… captured on 2024-12-18 at 01:49:01.

View Raw

More Information

-=-=-=-=-=-=-


Here is a sample program to delete all the files in a subdirectory.
I'm typing it in off the top of my head, so I make no claims about its
accuracy and I haven't tested it.  It deliberately avoids nested
subdirectories - you would need to do some kind of depth first
recursion loop so that the innermost directories were deleted first, or
doing an initial pass to build up a list of directories to delete.

10 D$=CHR$(4)
20 PRINT D$;"PREFIX": INPUT PR$
30 PRINT "Prefix is: ";PR$: PRINT
40 INPUT "Directory to delete?";DN$
50 IF DN$ = "" THEN END
60 IF RIGHT$(DN$,1) <> "/" THEN DN$ = DN$ + "/"
70 SD% = 0
80 PRINT D$;"OPEN ";DN$;",TDIR"
90 PRINT D$;"READ ";DN$
100 INPUT A$: REM directory name
110 INPUT A$: REM heading line
120 INPUT A$: REM blank line
130 INPUT L$: REM file line or trailing blank line
140 IF L$="" THEN GOTO 200
150 IF MID$(L$,18,3) = "DIR" THEN SD% = 1: GOTO 130
160 F$ = DN$ + MID$(L$,2,15)
170 IF LEFT$(L$,1) = "*" THEN PRINT D$;"UNLOCK ";F$
180 PRINT D$;"DELETE ";F$
190 GOTO 130
200 PRINT D$;"CLOSE"
210 IF SD% THEN PRINT "Further subdirectories need to be deleted": END
220 PRINT D$;"UNLOCK ";DN$
230 PRINT D$;"DELETE ";DN$
240 END


The "/" added in line 60 is to simplify later code, but isn't required
for opening the directory.


An aside: the above program also demonstrates how to read a catalog in
a ProDOS BASIC program.  You open the directory as if it was a text
file (but specify a type of DIR), then READ it and use INPUT to
process each line.  The lines are the same as those returned by the
80-column catalog listing, in the following order:

Directory name (e.g. "/RAM5")
Catalog heading (" NAME            TYPE " etc.)
A blank line
One line for each file in the directory "*BASIC.SYSTEM      SYS " etc.)
A blank line
The block usage line ("BLOCKS FREE: 1500" etc.)


You can use LEFT$, RIGHT$ and MID$ to pick the necessary fields from
the file lines.  Don't forget to close the directory after you've
finished reading from it.

(There is no comparable method of doing this in DOS 3.3.)
-- 
David Empson
dempson@actrix.gen.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand