home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
killold1.zip
/
KILLOLD.CMD
next >
Wrap
OS/2 REXX Batch file
|
1996-06-11
|
5KB
|
161 lines
/* rexx file to kill old files left lying around */
/* trace results */
/*
will take either a directory name and the "age" in days or a file
with a list of directory names and "age" days. It differentiates
between the two formats by what you pass it. Either a directory
or a file name. If you pass it a listfile *and* an "age" parm it
will use the "age" as a default for each of the directories in the
listfile - which can be overridden inside the listfile.
Requirements:
RexxUTIL.DLL - shipped with OS/2
RxDates.cmd - date manipulation rexx file.
*/
/* setup stuff */
basedir=directory()
env='OS2ENVIRONMENT'
signal on halt name errortrap
signal on syntax name errortrap
parse source . how myfile /* how was I called? from Command line or rexx program */
mypath=filespec('D',myfile) || filespec('P',myfile)
parse value filespec('N',myfile) with myname '.' myextn
call postlog myname 'Checking for out of date files.'
if right(mypath,1)='\' then mypath=left(mypath,length(mypath)-1) /* should be my directory */
call directory(mypath) /* now in directory where I started from. this gives me access to RxDates.cmd */
call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call SysLoadFuncs
if \exist('RxDates.cmd') then
do
say
say 'Missing required file RxDates.cmd! Should be in the 'mypath' directory.'
say
call error
end /* do */
parse upper arg dirlist defaultage
if length(dirlist)<1 then call error
rc=sysfiletree(dirlist,filestem,'OD') /* is this a directory? */
if filestem.0>0 then /* this is a directory, process directly */
do
call do_dir dirlist defaultage
exit
end /* do */
else /* hopefully this is a listfile */
rc=sysfiletree(dirlist,filestem,'OF') /* is this a file? */
if filestem.0=1 then
do while lines(dirlist)>0 /* listfile processing */
drop dirname age
parse value linein(dirlist) with dirname age .
if length(age)<1 then age=defaultage
if left(dirname,1) <> ';' then call killem dirname age /* allow for comments in list file */
end /* do */
else call error
call postlog myname 'Complete.'
call directory(basedir)
exit
do_dir:
arg dir_spec age
rc=sysfiletree(dir_spec,dirstem2,'OD') /* is this a directory? */
do x=1 to dirstem2.0 /* handle wildcards too! */
call killem dirstem2.x age
end /* do */
return
killem:
arg targetdir daysold
if length(daysold)<1 then call error
if \datatype(daysold,'N') then call error
too_old=date('b')-daysold
old_date=rxdates(too_old 'F')
if right(targetdir,1)<>'\' then targetdir=targetdir || '\'
say 'Scanning directory 'targetdir' for files older than 'old_date
call postlog 'Scanning directory 'targetdir' for files older than 'old_date
rc=sysfiletree(targetdir || '*',kill_list,'F')
if kill_list.0=0 then return
do i=1 to kill_list.0
parse var kill_list.i fdate ftime fsize fflags ffile .
fdate=translate(fdate,'/',':')
if too_old > Rxdates(fdate 'B') then
do
call postlog 'Deleting 'ffile' because it is older than 'rxdates(too_old 'U')
call sysfiledelete(ffile)
end /* do */
end /* do */
return
error:
do /* neither a listfile or a directory - exit */
say ''
say
say ' ***CAUTION*** ***ATTENTION*** ***WARNING*** '
say
say ' THIS PROGRAM IS ACTUALLY DESIGNED TO ERASE FILES FROM YOUR SYSTEM ON '
say ' A CONTROLLED BASIS. IMPROPER OR CAUSAL USE OF THIS PROGRAM CAN REMOVE '
say ' FILES THAT YOU MAY HAVE INTENDED TO KEEP. MAKE SURE YOU KNOW EXACTLY '
say ' WHAT YOU ARE DOING WHEN YOU USE THIS PROGRAM. '
say
say ' YOU HAVE BEEN WARNED. '
say
say ' ***CAUTION*** ***ATTENTION*** ***WARNING*** '
say
say
say ' Invalid parms. '
say
say ' This program will delete all files from a directory that are <age> days old. '
say
say ' Format is 'myname' <directory> <age>'
say ' or '
say ' 'myname' <listfile> <age>'
say ' where <listfile> contains a list of directories and age.'
say
say ''
call postlog myname 'Parameter Error.'
call directory(basedir)
exit
end /* do */
return
/* test for the existance of a file - return true or false condition */
exist: procedure
arg filenameexist
return \(stream(filenameexist,'c','query exists')='')
/* error trap for rexx failures */
errortrap:
call postlog myname 'Code Error.'
call postlog 'ERROR in batch file at line 'sigl
call postlog condition('C') condition('D') condition('I')
exit
return