[fa.info-vax] Deleting directory trees

iglesias@UCI-ICSA.ARPA (Mike Iglesias) (10/08/85)

Does anyone have a DCL procedure that, given a starting directory (not
necessarily a top level directory), will delete all files and directories
under that starting directory?  If so, can you mail a copy to me?

Thanks,

Mike Iglesias
University of California, Irvine
iglesias@uci-icsa.arpa

jeff@ISI-VAXA.ARPA (Jeffery A. Cavallaro) (10/09/85)

I used to have a huge recursive command procedure, but then I found:

$ set file/nodirectory <target>
$ delete <target>

This seems to work.  I am not sure what happens to all the levels
underneath <target>, but they seem to go away.  Maybe someone else
out there knows.

As a side note, I am not sure why:

	DELETE [...]*.*;*

doesn't work.  It seems to handle the first instance of a subdirectory,
but bombs on all subsequent.  For example:

          A
         / \
        B   C

B will be deleted, but the DELETE command fails on C.
Any ideas???

					Jeff

OC.GARLAND@CU20B.COLUMBIA.EDU (Richard Garland) (10/09/85)

Mike:

This works.  Take out the bells (really) and "/log"'s if you prefer.

$!..DELDIR.COM			Delete directory and all its files
$!				R. Garland	Columbia Chem. Dept.
$ SAVE_VERIFY	=	'F$VERIFY(0)
$ SET		NOON
$ INQUIRE	NAME	"DELDIR> Directory to be deleted (no brakets) "
$ IF		NAME .EQS. ""	THEN EXIT
$ INQUIRE	DEV	"DELDIR> Disk on which it resides (default USER$, no brakets) "
$ IF		DEV .EQS. ""	THEN DEV := USER$
$ SET DEFAULT	'DEV':['NAME']
$ If P1 .eqs. "NOUNPROTECT" Then	GoTo Delete
$ Write Sys$Output	" "
$ Write	Sys$Output	"[ Unprotecting ... ]"
$ Write Sys$Output	" "
$ SET PROT=(SYS:RWED)	[...]*.*;*
$ Delete:
$ Write Sys$Output	" "
$ Write	Sys$Output	"[ Deleting ... ]"
$ Write Sys$Output	" "
$ 	DELETE		[...]*.*;*/Log
$ If .not. $Status 	Then GoTo Delete
$ Write Sys$Output	" "
$ Write	Sys$Output	"[ Done ]"
$ Write Sys$Output	" "
$ SET DEFAULT	[-]
$ NL	=	'F$LEN(NAME)
$ LP	=	'F$LOC(".",NAME)'
$ IF LP .EQ. NL THEN GOTO DELDIR1
$ OFF	=	LP+1
$ LEN	=	NL-LP
$ NAME  :=	'F$EXT(OFF,LEN,NAME)
$ DELDIR1:
$ SET PROT=(SY:RWED)	'NAME'.DIR;1
$ DELETE/LOG		'NAME'.DIR;1
$!
$! SET DEFAULT	Sys$Manager:
$ !	'F$VERIFY(SAVE_VERIFY)
$ EXIT
-------

iglesias@UCI-ICSA.ARPA (Mike Iglesias) (10/09/85)

I've received many responses to my request for a DCL procedure
to delete directory trees, and not one of the DCL procedures is the same!
Thanks to one and all for your help.

Mike Iglesias
University of California, Irvine

OC.GARLAND@CU20B.COLUMBIA.EDU (Richard Garland) (10/10/85)

Ouch!!!!

If you set the directory /NODIRECTORY and delete it all the files
underneath DO NOT GO AWAY.  They just become LOST.  Doing this
will fill you disk with lost files which you wont see but which
take up space.  To get them you must

	ANAL/DISK/REPAIR

(might want to use veirfy mode) and then delete those files when they
get put into SYS$LOST.

Setting a directory /NODIRECTORY is a last resort if the file is corrupt
and you must get rid of it.

					Rg
-------

ss@wanginst.UUCP (Sid Shapiro) (10/10/85)

I noticed that most of the procs that were sent to the net (of the
ones that worked and weren't destructive) suffered from the VMSish
characteristic of being very verbose!  I see no reason why such a proc
must give lots of feedback.  rm -r doesn't,  and I like that,
so my proc, which is different from all of the ones I've seen 
so far, doesn't either.  (And it doesn't ask any question either!)

$ voff					! A proc to turn off verify mode
$ set default [.'p1']			! Assume a relative directory, I
$					! hardly ever remove an absolute
$					! directory.
$another_dir:
$ file = f$search("*.dir")		! Find a subdirectory
$ if file .eqs. "" then goto no_dirs	! Good, there are none.
$ dfile = f$parse(file,,,"name")	! Get its name
$ rmdir 'dfile'				! Recursively delete
$					! everything in it
$ goto another_dir			! Get the next one.
$
$no_dirs:				! Only files left.
$ delete *.*;*				! Zap them all.
$ set default [-]			! Move back to where we were
$					! when we started.
$ set protection=s:d 'p1'.dir;*		! Fix the directory protection
$ delete 'p1'.dir;*
$ vres					! Proc to restore verify mode
% 
/ Sid /