From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 29-JUL-1989 20:56
To:	MRGATE::"ARISIA::EVERHART"
Subj:	RE: deleting files

Message-Id:  <8907300051.AA27971@crdgw1.ge.com>
Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Sat, 29 JUL 89 17:14:43 PDT
Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Sat, 29 Jul 89 16:49:25 PDT
Received: from UALR.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 2266; Sat, 29 Jul 89 19:50:29 EDT
Date: Sat, 29 Jul 89 18:47 CST
From: Dale Miller <DOMILLER%UALR.BITNET@CUNYVM.CUNY.EDU>
Subject: RE: deleting files
To: INFO-VAX@KL.SRI.COM
X-Vms-To: IN%"INFO-VAX@KL.SRI.COM"

>Is there a way to recursively remove a directory and all the files under
>it?  Right now, I use the following,
>
>       del [...]*.*;*                  - delete all files
>       set file/prot [...]*.*;*        - make directories deletable
>       del [...]*.*;*                  - delete leaf directories
>
>And repeat the last step until there are no more directories left to
>delete.  Surely there must be a less cumbersome approach.
>
>Thanks.
>
> -----------------------------------------------------------------------------
>|  David C. Brown              |  uunet!mnetor!motto!dave                    |
>|  Motorola Canada, Ltd.       |  416-499-1441 ext 3708                      |
>|  Communications Division     |  Disclaimer: Motorola is a very big company |
> -----------------------------------------------------------------------------

While there is a .COM procedure in the VMS doc set, it is not particularly
efficient.  Since we delete several hundred directories at the end of each
semester, I wrote a procedure to do it much quicker.  Following is the DELTREE
distribution.

--------------------------------------------------------------------------
| Dale O. Miller                        | #   #  ###  #     ####         |
| University of Arkansas at Little Rock | #   # #   # #     #   #        |
| 2801 S. University                    | #   # ##### #     ####         |
| Little Rock, AR  72204-1099  USA      | #   # #   # #     #  #         |
| (501)569-8714                         |  ###  #   # ##### #   #        |
| DOMILLER@UALR.BITNET                  | Disclaimer: This does not      |
| 92-20-28 W,34-43-30 N.ICBMNET         | say what I say it doesn't say. |
--------------------------------------------------------------------------
$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user DOMILLER
$! on 29-JUL-1989 18:39:38.40.
$!
$! It contains the following 3 files:
$!        AAAREADME.DOC
$!        DELTREE.CLD
$!        DELTREE.PLI
$!
$!============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part )
); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER( 1
); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT;
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START:
$ FILE_IS = "AAAREADME.DOC"
$ CHECKSUM_IS = 1534423322
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X               DELTREE - Delete a directory tree                 30-Sep-1986
X
X           Dale Miller - University of Arkansas at Little Rock
X
X    This directory contains a directory-deletion program that is much more
Xefficient than doing it in DCL.  Supplied files are:
X
X
XAAAREADME.DOC`009`009- This file
XDELTREE.CLD`009`009- Command definition for DELTREE.
XDELTREE.EXE`009`009- Exacutable for those of you who don't have PL/I.
XDELTREE.PLI`009`009- PL/I source for DELTREE.
X
V    Just copy deltree.exe to sys$system and type "SET COMMAND DELTREE" and yo
Xu
Vare ready to go deleting directories full of files.  Alternately, you may loc
Xate
XDELTREE.EXE elsewhere as long as you change the CLD.  You may also merge the
Vsupplied CLD into DCLTABLES and everyone can then use it.  Ther is no HELP fi
Xle,
Vbut the only qualifier allowed is /LOG.  Any valid VMS directory may be delet
Xed.
$ GOSUB UNPACK_FILE

$ FILE_IS = "DELTREE.CLD"
$ CHECKSUM_IS = 930023569
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XDEFINE VERB DELTREE
X`009IMAGE `009`009"sys$system:DELTREE.EXE"
X`009PARAMETER`009P1  LABEL=DIRECTORY, PROMPT="Directory", VALUE(REQUIRED)
X`009QUALIFIER`009LOG
$ GOSUB UNPACK_FILE

$ FILE_IS = "DELTREE.PLI"
$ CHECKSUM_IS = 994228272
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/************************************************************************/
X/*`009`009`009`009`009`009`009`009`009*/
X/*`009Deltree.pli`009`009`009`009`009`009`009*/
X/*`009This program will delete a directory tree.`009`009`009*/
X/*`009Dale Miller - UALR`009`009`009`009`009`009*/
X/*`00920-Jul-1986`009`009`009`009`009`009`009*/
X/*`009`009`009`009`009`009`009`009`009*/
X/*`009Rev. 1.0  20-Jul-1986`009`009`009`009`009`009*/
X/************************************************************************/
XDELTREE: PROC OPTIONS(MAIN);
X
X`009%INCLUDE $RMSDEF;
X`009%INCLUDE $CLIDEF;
X
X`009DCL LIB$FIND_FILE`009`009EXTERNAL ENTRY(CHAR(*),
X`009`009`009`009`009CHAR(*),
X`009`009`009`009`009FIXED BIN(31))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL LIB$DELETE_FILE `009`009EXTERNAL ENTRY(CHAR(*))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL LIB$GET_FOREIGN`009`009EXTERNAL ENTRY(CHAR(*),
X`009`009`009`009`009CHAR(*),
X`009`009`009`009`009FIXED BIN(31))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL LIB$PUT_OUTPUT`009`009EXTERNAL ENTRY(CHAR(*))
X`009`009`009`009`009RETURNS (FIXED BIN(31));
X
X`009DCL CLI$GET_VALUE`009`009EXTERNAL ENTRY(CHAR(*),CHAR(*))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL CLI$PRESENT`009`009`009EXTERNAL ENTRY(CHAR(*))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL DIRNAM`009`009`009CHARACTER(255);
X`009DCL FILE_TO_DELETE`009`009CHARACTER(255);
X`009DCL DUMMY`009`009`009CHARACTER(255);
X`009DCL STATUS`009`009`009FIXED BIN(31);
X`009DCL IND`009`009`009`009FIXED BIN(31);
X`009DCL CONTEXT`009`009`009FIXED BIN(31);
X`009DCL LEN`009`009`009`009FIXED BIN(31);
X`009DCL I`009`009`009`009FIXED BIN(31);
X`009DCL LOG`009`009`009`009BIT(1);
X
X`009LOG='0'B;
X`009IF(CLI$PRESENT('LOG')=261401) THEN LOG='1'B;
X
X`009STATUS = CLI$GET_VALUE('DIRECTORY',DIRNAM);
X
X`009LEN=INDEX(DIRNAM,']');
X`009IF(LEN=0)
X`009    THEN DO;
X`009`009PUT SKIP LIST('%DELTREE-E-INVDIR, Invalid directory name');
X`009`009GO TO FINISH;
X`009`009END;
X`009IF (SUBSTR(DIRNAM,LEN+1,255-LEN-1)`094=' ')
X`009    THEN DO;
X`009`009PUT SKIP LIST('%DELTREE-E-INVDIR, Invalid directory name');
X`009`009GO TO FINISH;
X`009`009END;
X
X`009IF(INDEX(DIRNAM,'.')=0)
X`009    THEN DO;
X`009`009IND=INDEX(DIRNAM,'[');
X`009`009IF(IND=0)
X`009`009    THEN DO;
X`009`009`009PUT SKIP LIST
X`009`009`009    ('%DELTREE-E-INVDIR, Invalid directory name');
X`009`009`009GO TO FINISH;
X`009    `009    END;
X`009`009`009
X`009`009FILE_TO_DELETE=SUBSTR(DIRNAM,1,IND-1)`124`124'[000000]'`124`124
X`009`009    SUBSTR(DIRNAM,IND+1,INDEX(DIRNAM,']')-IND-1)`124`124'.DIR;*';
X`009`009END;
X`009    ELSE DO;
X`009`009DO I = LEN TO 1 BY -1 UNTIL (SUBSTR(DIRNAM,I,1)='.');
X`009`009END;
X`009`009FILE_TO_DELETE=SUBSTR(DIRNAM,1,I-1)`124`124']'`124`124
X`009`009    SUBSTR(DIRNAM,I+1,LEN-I-1)`124`124'.DIR;*';
X`009`009END;
X
X`009STATUS = LIB$FIND_FILE (FILE_TO_DELETE, DUMMY,
X`009    CONTEXT);
X`009IF(STATUS `094= RMS$_NORMAL)
X`009    THEN DO;
X`009`009PUT SKIP LIST('%DELTREE-E-INVDIR, Invalid directory name');
X`009`009GO TO FINISH;
X`009`009END;
X
X`009CALL DELROUT(SUBSTR(DIRNAM,1,INDEX(DIRNAM,' ')-1));
X
X`009IF(LOG) THEN PUT SKIP EDIT('%DELTREE-I-DELFIL, Deleting ',
X`009    SUBSTR(DUMMY,1,INDEX(DUMMY,' ')-1))(A,A);
X`009STATUS = LIB$DELETE_FILE(DUMMY);
X
XDELROUT: PROC(DIRNAM) RECURSIVE;
X
X`009%INCLUDE $RMSDEF;
X
X`009DCL LIB$FIND_FILE`009`009EXTERNAL ENTRY(CHAR(*),
X`009`009`009`009`009CHAR(*),
X`009`009`009`009`009FIXED BIN(31))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL LIB$DELETE_FILE `009`009EXTERNAL ENTRY(CHAR(*))
X`009`009`009`009`009RETURNS(FIXED BIN(31));
X
X`009DCL DIRNAM CHARACTER(*);
X`009DCL FILE_TO_DELETE`009`009CHARACTER(255);
X`009DCL FNAME`009`009`009CHARACTER(255) VARYING;
X
X`009DCL STATUS`009`009`009FIXED BIN(31);
X`009DCL IND`009`009`009`009FIXED BIN(31);
X `009DCL CONTEXT`009`009`009FIXED BIN(31);
X
X`009STATUS = RMS$_NMF;
X`009CONTEXT = 0;
X
X`009STATUS = LIB$FIND_FILE (DIRNAM`124`124'*.*;*', FILE_TO_DELETE,
X`009    CONTEXT);
X
X`009DO WHILE((STATUS `094= RMS$_NMF)&(STATUS `094= RMS$_FNF));
X
X`009    IF(INDEX(FILE_TO_DELETE,'.DIR;') `094=0)
X`009`009THEN DO;
X`009`009    IND=INDEX(FILE_TO_DELETE,']');
X`009`009    FNAME=SUBSTR(FILE_TO_DELETE,IND+1,
X`009`009`009INDEX(FILE_TO_DELETE,';')-IND-5);
X`009`009    CALL DELROUT(SUBSTR(FILE_TO_DELETE,1,IND-1)`124`124
X`009`009`009'.'`124`124FNAME`124`124']');
X`009`009    END;
X`009    IF (LOG) THEN PUT SKIP EDIT
X`009`009('%DELTREE-I-DELFIL, Deleting ',SUBSTR(FILE_TO_DELETE,1,
X`009`009INDEX(FILE_TO_DELETE,' ')-1))(A,A);
X
X`009    STATUS = LIB$DELETE_FILE(FILE_TO_DELETE);
X
X`009    STATUS = LIB$FIND_FILE (DIRNAM`124`124'*.*;*', FILE_TO_DELETE,
X`009`009CONTEXT);
X`009    END;
X
X
XEND DELROUT;
XFINISH:
XEND DELTREE;
$ GOSUB UNPACK_FILE
$ EXIT


