home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
netdor2.zip
/
DISK_10
/
IMAGE9.ZIP
/
DELDIR.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-08-17
|
6KB
|
183 lines
/*****************************************************************************
* DELDIR - Delete Directory Tree *
* T. Bridgman (CORE at WATSON) *
* Copyright (c) IBM Corporation, 1992. All rights reserved. *
*****************************************************************************
* Licensed Materials-Property of IBM *
* 5604-472 (c) Copyright IBM Corporation, 1993 *
* All rights reserved. *
* US Government Users Restricted Rights - *
* Use, duplication or disclosure restricted *
* by GSA ADP Schedule Contract with IBM Corp. *
*****************************************************************************
* REQUIRES: RXUTILS.DLL, DATECONV.CMD *
*****************************************************************************
* Version 1.0 - 6 Jan 92 *
* 7 Jan 91 - teb *
* - Add /R option to not delete root directory of tree after emptying. *
* - Properly qualify relative directory names (C:\.\.). *
* 4 May 92 - teb *
* - Delete empty directories when /D specified. *
* - Clear attributes of files. *
* - Scan root of tree when /D specified. *
* 13 Nov 92 - teb *
* - Handle directories with spaces in the name. *
* 10 Aug 93 - teb *
* - Change Q options to S. *
*****************************************************************************/
trace 'O'
parse upper arg Dir '/' Opts
if Dir = '?' | Dir = ''
then signal Tell
call rxfuncadd 'RXLOADFUNCS', 'RXUTILS', 'RXLOADFUNCS'
call RxLoadFuncs
say
Dir = ParseOpts(Dir, Opts)
say 'Delete directory tree:' Dir
if Opt.!Query
then do
call rxSay 'Shall we continue? '
do until wordpos(Ch, 'Y N') <> 0
Ch = translate(rxGetKey('NOECHO'))
end
say Ch
if Ch = 'N'
then exit 2
end
if right(Dir, 1) = '\'
then Dir = left(Dir, length(Dir)-1)
if Opt.!Age <= 0
then call DelTree Dir
else do
if Opt.!Dir
then rc = rxTree(Dir'\*', 'DATA.', 'BT',,'-*---')
else rc = rxTree(Dir'\*', 'DATA.', 'BST',,'-*---')
CutOff = dateconv(date('O'), 'O', 'O',, '-'Opt.!Age)'/00/00'
call rxStemSort 'DATA.', 'A', 1, 14
do I = 1 to Data.0 while word(Data.I, 1) < CutOff
Spec = subword(Data.I, 4)
IsDir = (pos('D', word(Data.I, 3)) > 0)
if IsDir
then if Opt.!Dir
then do
say '*** Deleting directory tree' Spec':'
call DelTree Spec
call RmDir Spec
end
else call RmDir Spec
else call DelFile Spec
end
end
exit 0
DelTree: procedure expose Opt.
parse arg Dir
if right(Dir, 1) = '\'
then Dir = left(Dir, length(Dir)-1)
rc = rxTree(Dir'\*', 'FILES.', 'BS',,'-*----')
do I = Files.0 to 1 by -1
parse var Files.I . . . Flags File
File = strip(File)
if pos('EA DATA. SF', translate(File)) > 0
then if Opt.!FMsg
then say File '... skipped'
else nop
else if pos('D', Flags) > 0
then call RmDir File
else call DelFile File
end
if Opt.!DelRoot
then call RmDir Dir
return 0
DelFile: procedure expose Opt.
parse arg FName
rc = rxDelete(FName)
if Opt.!FMsg
then say FName '... rc('rc')'
return rc
RmDir: procedure expose Opt.
parse arg DirName
'@RD "'DirName'" > NUL 2>&1'
if Opt.!DMsg
then say DirName '... ('rc')'
return rc
ParseOpts: procedure expose Opt.
parse arg Dir, Opts
parse value '1 0 0 1 1' with Opt.!Query Opt.!Age Opt.!Dir Opt.!FMsg,
Opt.!DMsg
Dir = strip(Dir)
Dir = strip(Dir,,'"')
Home = directory()
Test = directory(Dir)
if Test = ''
then do
say 'Directory' Dir 'does not exist.'
exit 10
end
Dir = Test
Opt.!DelRoot = (length(Dir) > 3)
call directory left(Dir, 3)
call directory Home
Opts = translate(Opts, '/', '-')
if Opts <> ''
then do while Opts <> ''
parse var Opts Opt '/' Opts
parse var Opt Opt OptArg
select
when Opt = 'B'
then Opt.!Query = 0
when abbrev('AGE', Opt)
then Opt.!Age = OptArg
when abbrev('DIR', Opt)
then Opt.!Dir = 1
when Opt = 'S' | Opt = 'Q'
then Opt.!FMsg = 0
when Opt = 'SS' | Opt = 'QQ'
then do
Opt.!FMsg = 0
Opt.!DMsg = 0
end
when Opt = 'R'
then Opt.!DelRoot = 0
otherwise do
say 'Unrecognized option' Opt'.'
exit 10
end
end
end
return Dir
Tell:
say
say 'DELDIR - Delete a complete directory tree'
say
say 'Syntax: DELDIR directory [/B] [/Age <days> [/Dir]] [/Q[Q]] [/R]'
say
say 'Delete all files and subdirectories under the specified directory.'
say
say 'Options (which may be entered in any order):'
say ' /B'
say ' - Bypass the "are you sure" query -- dangerous!'
say ' /Age <days> [/Dir]'
say ' - Only delete files that are older than the specified number of days.'
say ' This option will slow down processing considerably.'
say ' - If /D is specified, all directories *immediately* off of the'
say ' specified target that were created more than the specified'
say ' number of days will be completely deleted, even if they contain'
say ' files or directories that are newer than the cutoff date.'
say ' /S[S]'
say ' - If /S is specified, no deletion message is given for each file.'
say ' - If /SS is specified, messages for directories are supressed'
say ' as well.'
say ' /R'
say ' - Don''t delete the specified directory after emptying it. (Assumed'
say ' when the root directory is specified.'
exit 0