$! DELTREE.COM -- Delete a Directory Tree Command Procedure
$ say = "write sys$output"
$ fac = "%DELTREE-"
$ exit_status = 1
$ on control_y then $ goto fatal_exit
$ on warning then $ goto fatal_exit
$ if f$type (deltree) .eqs. ""
$ then
$ deltree = "@" + f$environment ("procedure")
$ endif
$ req_privs = "tmpmbx,netmbx,bypass"
$ old_privs = f$setprv (req_privs)
$ if .not. f$privilege (req_privs) then $ goto no_priv
$ exit_status = 1
$ saved_dir = f$environment ("default")
$ root_dir = f$edit (p1,"trim,upcase")
$ if root_dir .eqs. "" then $ inquire root_dir "Root directory"
$ if root_dir .eqs. "" then $ goto final_exit
$ delete_option = f$edit (p2,"trim,upcase")
$ if delete_option .eqs. "" then -
$ inquire delete_option -
"Delete command option (C - Confirm, L - Log, N - Nolog) [C]"
$ if delete_option .eqs. "" then $ delete_option = "C"
$ delete_qual = ""
$ if delete_option .eqs. "C" then $ delete_qual = "/confirm"
$ if delete_option .eqs. "L" then $ delete_qual = "/log"
$ if delete_option .eqs. "N" then $ delete_qual = "/nolog"
$ if delete_qual .eqs. "" then $ goto invalid_option
$end_get_qual:
$ if f$parse (root_dir) .eqs. "" then $ goto bogus_root
$ set default 'root_dir'
$ this_dir = (f$directory () - "]" - ">") - (f$parse ("[-]",,,"directory") -
- "]" - ">") - "." - "["
$!
$directory_loop:
$ file_spec = f$search ("*.DIR;1")
$ if file_spec .eqs. "" then $ goto end_directory_loop
$ dir_name = f$parse (file_spec,,,"name")
$ if f$search ("[.''dir_name']*.*") .nes. "" then $ goto down_tree
$ set file 'dir_name'.dir;1 /nodirectory/prot=(s:rwed,o:rwed)
$ delete_'delete_qual' 'dir_name'.dir;1
$ goto directory_loop
$down_tree:
$ deltree [.'f$parse (file_spec,,,"name")'] 'delete_option'
$ goto directory_loop
$end_directory_loop:
$!
$ if f$search ("*.*") .eqs. "" then $ goto no_files
$ set prot=(s:rwed,o:rwed) *.*;*
$ delete_'delete_qual' *.*;*
$no_files:
$ set file [-]'this_dir'.dir;1 /nodirectory/prot=(s:rwed,o:rwed)
$ delete_'delete_qual' [-]'this_dir'.dir;1
$final_exit:
$ if f$type (old_privs) .nes. "" then $ old_privs = f$setprv (old_privs)
$ set default 'saved_dir'
$ exit exit_status
$!
$! Errors:
$!
$fatal_exit:
$ say fac,"F-FATAL, unexpected error detected"
$ exit_status = %X10000004
$ goto final_exit
$invalid_option:
$ say fac,"E-INVOPT, invalid delete command option - use C, L, or N"
$ exit_status = %X10000002
$ goto final_exit
$bogus_root:
$ say fac,"E-NOSUCHDIR, no such directory ''root_dir'"
$ exit_status = %X10000002
$ goto final_exit
$no_priv:
$ say fac, "E-NOPRIV, insufficient privilege (need ''req_privs')"
$ exit_status = %X10000002
$ goto final_exit
$!++
$! DELTREE.COM -- Delete a Directory Tree Command Procedure
$!
$! This command procedure is invoked as follows to delete a directory
$! tree:
$!
$! @site_tools:deltree root delete-option
$!
$! where 'root' is the root directory of the tree to be deleted and
$! 'delete-option' determines what command qualifiers are appended to
$! the DELETE command as it is executed, C (for confirm), L (for log)
$! or N (for nolog). C (/CONFIRM) is the default.
$!
$! For example, type
$!
$! @site_tools:deltree disk4c:[smitty] n
$!
$! to delete the directory tree beginning at [SMITTY] on disk DISK4C
$! with no logging. The command procedure deletes all files in the tree,
$! including directories, starting at the bottom of the tree and working
$! upwards.
$!--
$! Revision history:
$!
$! V1.0 07-JUL-1983 David M. Smith - plagiarized from VMS System
$! Management Guide.
$!
$! V1.1 25-JUL-1983 David M. Smith - revised for standard definition of
$! MGR_LIBRARY.
$!
$! V2.0 13-DEC-1984 David M. Smith - handle .DIR files which are not
$! directories; add NOLOG option.
$!
$! V2.1 21-JUN-1985 David M. Smith - remove message if can't get SYSPRV;
$! turn on SYSPRV before starting to prevent spurious
$! errors for non-existent directories.
$!
$! 13-APR-1987 David M. Smith - revise for SITE changes; change
$! check for empty directory; fix to handle bad, real
$! directories; change P2 to work similar to RSS' DELTREE;
$! require BYPASS so protections need not be changed.
$!