home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
do_98359.zip
/
DELOLDER.CMD
Wrap
OS/2 REXX Batch file
|
1998-12-26
|
6KB
|
275 lines
/*
* Pgm Name : E:\DB\BATCH\CMD\PPWIZARD.CMD
* Pgm Version : 98.355
* Time : Saturday, 26 Dec 1998 2:28:22pm
* Input File : E:\DB\PROJECTS\OS2\delolder\DELOLDER.x
* Output File : .\OUT\DELOLDER.CMD
*/
/*
*$Header:E:/DB/PVCS.IT/OS2/DELOLDER/DELOLDER.X_V 1.1 25 Dec 1998 14:17:54 Dennis_Bareis $
*/
/*
*BASEDATE.XH Version 98.325 by Dennis Bareis
*http://www.ozemail.com.au/~dbareis(db0@anz.com)
*/
signal EndBASEDATEXh
FileBaseDate:Procedure
FileName=arg(1)
FileTime=stream(FileName, 'c', 'query datetime')
if FileTime= '' then
return(-1)
FileTime=space(FileTime)
parse var FileTime Month'-'Day'-'Year' 'Rest
if Year<80 then
Year=100+Year
Year=1900+Year
return(BaseDate(Year||Month||Day))
BaseDate:Procedure
TheDate=translate(arg(1), ' ', '/-')
if TheDate= '' then
TheDate=date('Sorted')
parse var TheDate Year MM DD
if length(Year)>=8 then
do
DD=substr(Year,7,2)
MM=substr(Year,5,2)
Year=left(Year,4)
end
DaysInMonth= '31 28 31 30 31 30 31 31 30 31 30 31'
if datatype(Year, 'WholeNumber')<>1 then
return(-10)
if datatype(MM, 'WholeNumber')<>1 then
return(-20)
if datatype(DD, 'WholeNumber')<>1 then
return(-30)
if MM<0|MM>12 then
return(-21)
DaysThisMonth=word(DaysInMonth,MM)
if MM=2 then
DaysThisMonth=DaysThisMonth+1
if DD<0|DD>DaysThisMonth then
return(-31)
if length(strip(Year))=2 then
do
if Year>=80 then
Year= '19' ||Year
else
Year= '20' ||Year
end
y=Year-0001
b=y*365
b=b+y%4
b=b-y%100
b=b+y%400
m=mm-01
do i=1 to m
b=b+word(DaysInMonth,i)
end
if mm>2 then
do
if 0=Year//4 then
do
if 0=Year//100 then
do
if 0=Year//400 then
b=b+1
end
else
b=b+1
end
end
d=dd-01
b=b+d
return(b)
BD2DATE:Procedure
b=arg(1)
Format=arg(2)
Delimiter=arg(3)
yy=1
n=400
d=n*365
d=d+n/4
d=d-n/100
d=d+n/400
w=b%d
b=b-w*d
yy=yy+w*n
n=100
d=n*365
d=d+n/4
d=d-n/100
w=b%d
b=b-w*d
yy=yy+w*n
n=4
d=n*365
d=d+n/4
w=b%d
b=b-w*d
yy=yy+w*n
n=1
d=n*365
w=b%d
w=min(3,w)
b=b-w*d
yy=yy+w*n
l=0
if 0=yy//4 then
do
if 0=yy//100 then
do
if 0=yy//400 then
l=1
end
else
l=1
end
if l then
p= '31 29 31 30 31 30 31 31 30 31 30 31'
else
p= '31 28 31 30 31 30 31 31 30 31 30 31'
do mm=1 to 12
d=word(p,mm)
if b<d then
leave
b=b-d
end
dd=b+1
yy=right(yy,4, '0')
mm=right(mm,2, '0')
dd=right(dd,2, '0')
if Format= 'DDMMYY' then
return(dd||Delimiter||mm||Delimiter||right(yy,2))
return(yy||Delimiter||mm||Delimiter||dd)
EndBASEDATEXh:
/*
*ADDCOMMA.XH Version 98.090 by Dennis Bareis
*http://www.ozemail.com.au/~dbareis(db0@anz.com)
*/
signal EndOfADDCOMMACode
AddCommasToDecimalNumber:procedure
NoComma=strip(arg(1))
if pos(',',NoComma)<>0 then
return(NoComma)
DotPos=pos('.',NoComma)
if DotPos=0 then
AfterDecimal= ''
else
do
if DotPos=1 then
return("0" ||NoComma)
AfterDecimal=substr(NoComma,DotPos+1)
NoComma=left(NoComma,DotPos-1)
end
NoComma=reverse(NoComma)
ResultWithCommas= ""
do while length(NoComma)>3
ResultWithCommas=ResultWithCommas||left(NoComma,3)|| ','
NoComma=substr(NoComma,4)
end
ResultWithCommas=ResultWithCommas||NoComma
ResultWithCommas=reverse(ResultWithCommas)
if AfterDecimal<> '' then
ResultWithCommas=ResultWithCommas|| '.' ||AfterDecimal
return(ResultWithCommas)
EndOfADDCOMMACode:
parse value arg(1)with MaxFileAge FileMasks
if FileMasks= "" then
call SyntaxError 'ERROR: Not enough parameters.', "SyntaxError (too few parms)"
if MaxFileAge<> '-' then
do
if DataType(MaxFileAge, 'Whole Number')=0 then
call SyntaxError 'ERROR: Invalid age of ' || MaxFileAge || '.', "SyntaxError (invalid age)"
end
AddRc=RxFuncAdd('SysFileTree', 'RexxUtil', 'SysFileTree')
AddRc=RxFuncAdd('SysFileDelete', 'RexxUtil', 'SysFileDelete')
TodaysBaseDate=BaseDate()
TotalFiles=0
TotalFilesDeleted=0
TotalFilesDelFailed=0
TotalFutureDated=0
do until FileMasks= ''
parse var FileMasks FileMask FileMasks
if left(FileMask,1)<> '+' then
Subdirs= ''
else
do
Subdirs= 'S'
FileMask=substr(FileMask,2)
end
call SysFileTree FileMask, 'FileName', 'FO' ||Subdirs
TotalFiles=TotalFiles+FileName.0
do i=1 to FileName.0
I2=(FileName.0-i)+1
FullFileName=FileName.I2
if MaxFileAge<> '-' then
do
FileBaseDate=FileBaseDate(FullFileName)
if FileBaseDate<0 then
iterate
FileAge=TodaysBaseDate-FileBaseDate
if FileAge<MaxFileAge then
do
if FileAge<0 then
TotalFutureDated=TotalFutureDated+1
iterate
end
end
if MaxFileAge= '-' then
call charout,'Deleting ' ||FullFileName
else
call charout,Bd2Date(FileBaseDate, 'DDMMYY', '/') || ': Deleting ' || FullFileName || ' (' || FileAge || ' days old)'
DeleteRc=SysFileDelete(FullFileName)
if DeleteRc<>0 then
do
call beep 4500,80
say ' - Failed (DOS RC = ' || DeleteRc || ')'
TotalFilesDelFailed=TotalFilesDelFailed+1
end
else
do
say ''
TotalFilesDeleted=TotalFilesDeleted+1
end
end
end
if(TotalFilesDeleted+TotalFilesDelFailed)<>0 then
say ''
say 'SUMMARY'
say '~~~~~~~'
if TotalFiles=0 then
say 'No files matched the mask!'
else
do
if MaxFileAge<> '-' then
say "Today's Date : " ||date()
say 'Total Files : ' ||AddCommasToDecimalNumber(TotalFiles)
if TotalFutureDated<>0 then
say 'Future Dated : ' ||AddCommasToDecimalNumber(TotalFutureDated)
say 'Files Deleted: ' ||AddCommasToDecimalNumber(TotalFilesDeleted)
if TotalFilesDelFailed<>0 then
say 'Delete Failed: ' ||AddCommasToDecimalNumber(TotalFilesDelFailed)
end
exit(TotalFilesDelFailed)
SyntaxError:
CmdRc=SIGL
say '[]--------------------------------------------------------------------------[]'
say '| DELOLDER.CMD: Version 98.359, (C)opyright Dennis Bareis 1998 |'
say '| http://www.labyrinth.net.au/~dbareis/index.htm (db0@anz.com) |'
say '[]--------------------------------------------------------------------------[]'
say ''
say 'This program deletes all files matching the mask if they are of a specified'
say 'minimum age in days. If you specify an age of "-" then all files matching'
say 'the mask will be deleted.'
say ''
say 'If "+" is specified on the FileMask then all subdirectories are processed.'
say ''
say 'CORRECT SYNTAX'
say '~~~~~~~~~~~~~~'
say ' DELOLDER[.CMD] AgeInDays [+]FileMask1 ...'
say ''
say ''
say arg(1)
exit(CmdRc)