Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!wupost!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@actrix.gen.nz (David Empson) Subject: Re: sub directories Message-ID: Organization: Actrix Information Exchange References: <1994May10.105354.2435@pro-haven.cts.com> Date: Fri, 20 May 1994 12:54:01 GMT Lines: 105 In article , Kid wrote: [Regarding deleting subdirectories] > Can't you just write zeros (or whatever the "free" indicator character is) > inthe space of the subdirectory using a block editor, and then it's > gone, whether it contained files or not? NO!!!! I'm not sure what you're suggesting to overwrite with zeros, but it is a bad idea whatever you mean. 1. If you meant overwriting the key block of the subdirectory: The root directory contains one entry which points to the subdirectory. If you tried to list the files in the overwritten subdirectory, ProDOS would probably return an error, if it didn't just hang. You would also end up with lots of blocks marked as "used" (belonging to the files that were in the subdirectory) but no longer accessible. 2. If you meant overwriting the root directory's entry for the subdirectory: You still end up with the "lost blocks" problem. You would also have an incorrect file count for the root directory. What is so hard about using normal ProDOS commands to delete the files inside the directory, and then deleting the directory? Many utility programs will do this automatically (e.g. Copy II+). If you don't have a program which can do this, and don't want to do it by hand, it is easy to write a BASIC program to delete all the files in a directory - see below. Why go to the trouble of using a block editor to do something that is likely to destroy the integrity of the file system on the disk? 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