home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
prune.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-05-04
|
5KB
|
130 lines
/* ------------------------------------------------------------------------ */
/* PRUNE.CMD */
/* */
/* PRUNE is a utility to remove directory trees. Everything below and */
/* including the directory passed to this routine is deleted and removed. */
/* */
/* Using SysFileTree Prune builds a list of the directories underneath the */
/* DirPathToPrune specified in the ARGument. For each directory found */
/* PruneIt will delete all the files within that directory and remove it. */
/* */
/* The directory tree built by SysFileTree is searched backwards because */
/* the subdirectories are listed in shallow to deep order. */
/* */
/* Maintenance */
/* ----------- */
/* 940701DS - #94DS18001 */
/* - Added logic to check the DirPathToPrune. The user cannot */
/* run PRUNE without an argument less than 4 bytes in length. */
/* */
/* 940908DS - #94DS25101 */
/* - Add logic to keep the directory the same on the target drive */
/* specified in the parameter. In other words when checking for */
/* the existence of the driectroy to be PRUNED return to the */
/* directory that was current before PRUNE was executed. */
/* */
/* ------------------------------------------------------------------------ */
Arg DirPathToPrune
Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
Call SysLoadFuncs
Say "Prune - Directory Tree Remover"
Say " "
if length(DirPathToPrune) < 1 then
Call NoFiles
else
if right(DirPathToPrune,1) = '\' then
Call ErrorMsg
else
Call PrunePath
exit
/* ------------------------------------------------------------------------ */
/* PrunePath */
/* */
/* ------------------------------------------------------------------------ */
PrunePath:
CurrentDir = directory()
TargetDir = filespec("drive",DirPathToPrune)
if TargetDir = '' then
TargetDir = CurrentDir
else
TargetDir = directory(TargetDir)
DirPathToPrune = directory(DirPathToPrune)
call directory TargetDir
call directory CurrentDir
if length(DirPathToPrune) > 0 then
do
if right(DirPathToPrune,1) = '\' then
do
Call ErrorMsg
Say " "
Say "NOTE: You may have tried to PRUNE a root directory which is NOT"
Say " allowed."
end
else
do
Say "Searching for files to Prune ..."
Call SysFileTree DirPathToPrune ||'\*.*', 'Dir', 'DSO'
Say "Pruning" DirPathToPrune ||"\*.* ..."
i = Dir.0
do while i > 0
"@ATTRIB -R -S -H" Dir.i||"\*.* > NUL"
Call PruneIt Dir.i
i = i - 1
end
Call PruneIt DirPathToPrune
end
end
else
Call NoFiles
Return
/* ------------------------------------------------------------------------ */
/* PruneIt */
/* */
/* ------------------------------------------------------------------------ */
PruneIt:
arg PruneDir
Call SysFileTree PruneDir||'\*.*', 'File', 'FO'
Say "Deleting" PruneDir||"\*.* ..."
Do j=1 to File.0
Call SysFileDelete(File.j)
End
Call SysRmDir(PruneDir)
Return
/* ------------------------------------------------------------------------ */
/* NoFiles */
/* */
/* ------------------------------------------------------------------------ */
NoFiles:
Say "No Files to PRUNE!"
Return
/* ------------------------------------------------------------------------ */
/* Error Message Routine */
/* ------------------------------------------------------------------------ */
ErrorMsg:
Say "The Directory path to Prune:[" || DirPathToPrune || "] is invalid!"
Say " "
Say "You must specify a subdirectory name at least 4 bytes long and it "
Say "must NOT end with a \"
Say " "
Say "Command Syntax: PRUNE subdirectoryname"
Say " "
Say " Example: PRUNE C:\TEMP"
Say " PRUNE \TEMP"
Say " PRUNE TEMP"
Return