From:	CSBVAX::MRGATE!info-vax-request@kl.sri.com@SMTP 29-FEB-1988 09:55
To:	ARISIA::EVERHART
Subj:	Re: recursive deletion


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri 26 Feb 88 13:49:34-PST
Received: by ucbvax.Berkeley.EDU (5.58/1.26)
	id AA26440; Fri, 26 Feb 88 07:41:36 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 25 Feb 88 00:31:22 GMT
From: whitfill@hc.dspo.gov  (Jim Whitfill)
Organization: Los Alamos National Laboratory
Subject: Re: recursive deletion
Message-Id: <14193@hc.DSPO.GOV>
References: <2202@bsu-cs.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

in article <2202@bsu-cs.UUCP>, cfchiesa@bsu-cs.UUCP (Sir Xetwnk) says:
> Posted: Wed Feb 24 11:18:01 1988
> 
> In article <567004@mail.uwa.oz>, j_smartt@mail.uwa.oz writes:
>> 
>> 
>> 
>> 
>> 
>> G'day!,
>> 	does anybody have a VMS/DCL procedure to simulate the UNIX
>> "rm -r *.*" command - i.e. to recursively remove all files at and below
>> a given directory?
>> 
>> Thanks,
>> Jeff.

The following is a program (recursive in DCL) and an associated sub-
program that will recursively delete directories and subdirectories,
including the root directory.




$	save_verify := 'f$verify(0)
$	set message/notext/noid/noseverity/nofacility
$ ! SYS$UTILS:[COMMANDS]DELTREE.COM
$ !
$ ! This command file (used recursively) will delete the contents of a root
$ ! directory, including the root directory and all subdirectories and files.
$ ! 
$ !
$ ! 		P1 = device:[directory] location of root directory
$ !		P2 = special delete switches, i.e. /BEFORE=YESTERDAY
$ !
$	set noon
$	batch = "NO"
$	if f$mode() .nes. "INTERACTIVE" then batch = "YES"
$	start_directory = f$logical("sys$disk") + f$directory()
$	wo := write sys$output
$	root = p1
$	if p1 .nes. "" then goto have_root
$ get_root:
$	if batch then wo "Directory not given in batch mode"
$	if batch then goto delete_done
$	inquire root "Enter DEVICE:[ROOT]"
$	if root .eqs. "" then goto delete_done
$ have_root:
$	colon = f$locate(":",root)
$	if colon .ne. f$length(root) then goto get_dir
$	wo "You must enter a DEVICE:"
$	goto get_root
$ get_dir:
$	device = f$extract(0,colon,root)
$	deldir = f$extract(colon+2,f$length(root)-colon-3,root)
$	define/user sys$output nl:
$	define/user sys$error nl:
$	directory 'root'
$	if $status .eq. %X00000001 .or. $status .eq. %X10018290 -
						then goto root_ok
$	wo "No such directory path ''root'"
$	if batch then goto delete_done
$	goto get_root
$ root_ok:
$	if batch then goto dont_check
$       wo ""
$       wo "              !!! NODE  ''f$logical("node")' !!!"
$       wo ""
$	wo "DELETE root dir, all subdirs and all files of ''root'"
$	inquire really "Are You SURE? [NO]"
$	if .not. really then goto delete_done
$ dont_check:
$	set def 'root'
$ !
$ !		Invoke recursive procedure to delete the directory tree
$ !		subject to any selection criteria in P2.
$ !
$	@sys$utils:[commands]deldirsub "''p2'"
$ !
$ !		Now get rid of top level directory
$ !
$	if f$locate(".",root) .ne. f$length(root) then goto sub_delete
$	set prot=sy:rwed 'device':[000000]'deldir'.dir;1
$	delete'p2' 'device':[000000]'deldir'.dir;1
$	if p2 .nes. "" then -
	wo "''device':[000000]''deldir'.dir;1 deleted, if created ''p2'"
$	if p2 .eqs. "" then -
	wo "''device':[000000]''deldir'.dir;1 deleted"
$	goto delete_done
$ sub_delete:
$	set default [-]
$	parent = f$directory()
$	parent = parent - "[" - "]"
$	deldir = deldir - parent - "."
$	set prot=sy:rwed 'device':'deldir'.dir;1
$	delete'p2' 'device':'deldir'.dir;1	
$	dot = f$locate(".",root)
$	root = f$extract(0,dot,root) + "]"
$	if p2 .nes. "" then -
	wo "''root'''deldir'.dir;1 deleted, if created ''p2'"
$	if p2 .eqs. "" then -
	wo "''root'''deldir'.dir;1 deleted"
$ delete_done:
$	set message/facility/text/severity/id
$	set def 'start_directory'
$	reset = f$verify(save_verify)
$ !		SYS$UTILS:[COMMANDS]DELDIRSUB.COM
$ !
$ !		This command file will recursively delete files in a dir tree
$ !		starting at the current directory.
$	set noon
$ !
$	dirtodelete = f$directory()
$ !
$ !		See if subdirectories exist and if so, go delete them.
$ !
$ sub_loop:
$	subdir = f$search("*.DIR;1")
	if subdir .eqs. "" then goto do_one
	subname = f$parse(subdir,,,"NAME")
	subdirect = dirtodelete - "]" + "." + subname + "]"
	set def 'subdirect'
	@sys$utils:[commands]deldirsub "''p1'"
	set def [-]
	goto sub_loop
$ do_one:
$ !
$ !		Delete all files subject to P1 qualifier (P2 may be null)
$ !
$	set proc/priv=bypass
$	delete'p1' *.*;*
$	set proc/priv=nobypass
$	write sys$output "All files deleted in ''dirtodelete' ''p1'"
$	exit
