[comp.os.vms] recursive deletion

j_smartt@mail.uwa.oz (02/19/88)

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.

cfchiesa@bsu-cs.UUCP (Sir Xetwnk) (02/25/88)

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.

Jeff, 

   You should be able to do that in DCL with the following commands:

$ SET DEFAULT directory_spec     ! If you're not there already
$ SET PROTECTION [...]*.*;*      ! If you don't already have Delete access
$ DELETE [...]*.*;*              ! May not delete non-empty .DIRs on frst pass,
                                   but then again maybe it will.  

It occurs to me that this may not be sufficient if you have more than one 
level of subdirectories to deal with; I haven't gotten that deep, myself.
I would think it would depend on whether or not VMS knows to delete what's
IN a subdirectory BEFORE trying to delete the subdirectory itself.  Anyone
who knows for sure, will doubtless post - I just felt that if the above
turns out to work, it's probably the shortest way at it.

Chris Chiesa
-- 
<><><><><><><><><><><><><><><><><><><><><><><><><><><><> Chris Chiesa <><><><><>
<> {ihpn4|seismo}!{iuvax|pur-ee}!bsu-cs!cfchiesa                              <>
<> cfchiesa@bsu-cs.UUCP                                                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

whitfill@hc.DSPO.GOV (Jim Whitfill) (02/25/88)

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

labovitz%etd1.DECnet@AFWAL-AAA.ARPA ("ETD1::LABOVITZ") (02/26/88)

>Date: 19 Feb 88 08:37:08 GMT
>From: munnari!mimir!wacsvax!effigy!mail!j_smartt@uunet.uu.net
>Subject: recursive deletion
>Message-Id: <567004@mail.uwa.oz>
>Sender: info-vax-request@kl.sri.com
>To: info-vax@kl.sri.com
>
>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.
>

Since  the DCL code that we use here at our site is so short, I am appending
it to this message.  This procedure will recursively delete all files
(including .DIR files) below the directory supplied in the call to the
procedure.  All usual (and unusual!) disclaimers apply to this code!!!

			LT Stuart L Labovitz
			USAF Avionics Laboratory
		arpa:	Labovitz%Etd2.decnet@Afwal-aaa.arpa
	(or, if you must, arpa:	Labovitzsl@Afwal-aaa.arpa	)
$!...................... Cut on the dotted line and save ......................
$! VAX/VMS archive file created by VMS_SHAR V-5.04 04-Feb-1988
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by LABOVITZ
$! on Thursday 25-FEB-1988 13:04:24.87
$!
$! It contains the following 1 file:
$! DELTREE.COM
$!=============================================================================
$Set Symbol/Scope=(NoLocal,NoGlobal)
$Version=F$GetSYI("VERSION")
$If Version.ges."V4.4" then goto Version_OK
$Write SYS$Output "Sorry, you are running VMS ",Version, -
", but this procedure requires V4.4 or higher."
$Exit 44
$Version_OK:CR[0,8]=13
$Pass_or_Failed="failed!,passed."
$Goto Start
$Convert_File:
$Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1:Define/User_Mode SYS$Output NL:
$Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$Delete VMS_SHAR_DUMMY.DUMMY;*
$Checksum 'File_is
$Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2:Return
$Start:
$File_is="DELTREE.COM"
$Check_Sum_is=1867668381
$Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ !     DELTREE.COM - deletes a complete directory tree
X$ !
X$ !     P1 = pathname of root of tree to delete
X$ !
X$ !     All files and directories in the tree, including
X$ !     the named root, are deleted.
X$ !
X$ IF "''DELTREE'" .EQS. "" THEN DELTREE = "@SYS$COMMON:[OPERATOR]DELTREE"
X$ ON CONTROL_Y THEN GOTO DONE
X$ ON WARNING   THEN GOTO DONE
X$ DEFAULT = F$LOGICAL("SYS$DISK") + F$DIRECTORY()
X$10:
X$ IF P1 .NES. "" THEN GOTO 20
X$ INQUIRE P1 "Root"
X$ GOTO 10
X$20:
X$ IF F$PARSE(P1) .EQS. "" THEN OPEN FILE 'P1'
X$ SET DEFAULT 'P1'
X$ show default
X$LOOP:
X$ FILESPEC = F$SEARCH("*.DIR;1")
X$ IF FILESPEC .EQS. "" THEN GOTO LOOPEND
X$ DELTREE [.'F$PARSE(FILESPEC,,,"NAME")']
X$ GOTO LOOP
X$LOOPEND:
X$ IF F$SEARCH("*.*;*") .NES. "" THEN DELETE *.*;*
X$ DIR = ((F$DIRECTORY()-"["-"]")-(F$PARSE("[-]",,,"DIRECTORY")-"["-"]")) -"."
X$ SET PROTECTION=WORLD:RWED [-]'DIR'.DIR;1
X$ DELETE/log [-]'DIR'.DIR;1
X$DONE:
X$ SET DEFAULT 'DEFAULT'
$GoSub Convert_File
$Exit              
------

terry@wsccs.UUCP (terry) (03/04/88)

In article <14193@hc.DSPO.GOV>, whitfill@hc.DSPO.GOV (Jim Whitfill) writes:
] in article <2202@bsu-cs.UUCP>, cfchiesa@bsu-cs.UUCP (Sir Xetwnk) says:
] > 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.
[an OBSCENELY large program which works nicely deleted]

Or you could log onto your Utrix system and do the following:

rm -rf VMSVAX::[DIR]

				:-)

			terry@wsccs

mb@tulane.tulane.edu (Mark Benard) (03/05/88)

In article <2202@bsu-cs.UUCP> cfchiesa@bsu-cs.UUCP (Sir Xetwnk) writes:
>In article <567004@mail.uwa.oz>, j_smartt@mail.uwa.oz writes:
>>
>>      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?
>>
>   You should be able to do that in DCL with the following commands:
>
>$ DELETE [...]*.*;*              ! May not delete non-empty .DIRs on frst pass,
>                                   but then again maybe it will.
>
To fully delete a directory DISK:[SMITH] (aka DISK:[000000]SMITH.DIR)
takes 3 commands

$ DELETE DISK:[SMITH...*]*.*.*      ! to get contents of subdirectories
$ DELETE DISK:[SMITH]*.*.*          ! to get contents of main directory
$ DELETE DISK:[000000]SMITH.DIR

which can be put in a command file as long as you do not branch on
warnings which will be generated by the first command if there are no
subdirectories.
-- 
Mark Benard
Department of Computer Science     INTERNET:   mb@TULANE.EDU
Tulane University                  USENET:     pyramid!tulane!mb
New Orleans, LA 70118              BITNET:     mb%TULANE.EDU@RELAY.CS.NET
				    (or pyramid!tulane!mb at DECWRL.DEC.COM)

whitfill@hc.DSPO.GOV (Jim Whitfill) (03/06/88)

in article <40@tulane.tulane.edu>, mb@tulane.tulane.edu (Mark Benard) says:
> 
> To fully delete a directory DISK:[SMITH] (aka DISK:[000000]SMITH.DIR)
> takes 3 commands
> 
> $ DELETE DISK:[SMITH...*]*.*.*      ! to get contents of subdirectories
> $ DELETE DISK:[SMITH]*.*.*          ! to get contents of main directory
> $ DELETE DISK:[000000]SMITH.DIR
> 
> which can be put in a command file as long as you do not branch on
> warnings which will be generated by the first command if there are no
> subdirectories.

You can't DELETE DISK:[SMITH...*]*.*;* if there is a subdirectory
in SMITH that contains files. DELETE will fail trying to delete
[SMITH]X.DIR since [SMITH.X] contains files. The only way to do this
is to use a recursive program that works its way to the bottom of the
tree and then deletes its way back up. Programs such as this have been
posted in this group.

                   =======================================
                               Jim A. Whitfill
                    Los Alamos National Laboratory (LANL)
                            Group MEE-10, MS J580
                             Los Alamos, NM 87545
                                (505) 667-9282

                 (ARPAnet ==> whitfill%meediv.xnet@lanl.gov)
                   =======================================