home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / do_98359.zip / DELOLDER.CMD
OS/2 REXX Batch file  |  1998-12-26  |  6KB  |  275 lines

  1. /*
  2.  * Pgm Name    : E:\DB\BATCH\CMD\PPWIZARD.CMD
  3.  * Pgm Version : 98.355
  4.  * Time        : Saturday, 26 Dec 1998  2:28:22pm
  5.  * Input File  : E:\DB\PROJECTS\OS2\delolder\DELOLDER.x
  6.  * Output File : .\OUT\DELOLDER.CMD
  7.  */
  8.  
  9. /*
  10. *$Header:E:/DB/PVCS.IT/OS2/DELOLDER/DELOLDER.X_V 1.1 25 Dec 1998 14:17:54 Dennis_Bareis $
  11. */
  12. /*
  13. *BASEDATE.XH Version 98.325 by Dennis Bareis
  14. *http://www.ozemail.com.au/~dbareis(db0@anz.com)
  15. */
  16. signal EndBASEDATEXh
  17. FileBaseDate:Procedure
  18. FileName=arg(1)
  19. FileTime=stream(FileName, 'c', 'query datetime')
  20. if FileTime= '' then
  21. return(-1)
  22. FileTime=space(FileTime)
  23. parse var FileTime Month'-'Day'-'Year' 'Rest
  24. if Year<80 then
  25. Year=100+Year
  26. Year=1900+Year
  27. return(BaseDate(Year||Month||Day))
  28. BaseDate:Procedure
  29. TheDate=translate(arg(1), ' ', '/-')
  30. if TheDate= '' then
  31. TheDate=date('Sorted')
  32. parse var TheDate Year MM DD
  33. if length(Year)>=8 then
  34. do
  35. DD=substr(Year,7,2)
  36. MM=substr(Year,5,2)
  37. Year=left(Year,4)
  38. end
  39. DaysInMonth= '31  28  31  30  31  30  31  31  30  31  30  31'
  40. if datatype(Year, 'WholeNumber')<>1 then
  41. return(-10)
  42. if datatype(MM, 'WholeNumber')<>1 then
  43. return(-20)
  44. if datatype(DD, 'WholeNumber')<>1 then
  45. return(-30)
  46. if MM<0|MM>12 then
  47. return(-21)
  48. DaysThisMonth=word(DaysInMonth,MM)
  49. if MM=2 then
  50. DaysThisMonth=DaysThisMonth+1
  51. if DD<0|DD>DaysThisMonth then
  52. return(-31)
  53. if length(strip(Year))=2 then
  54. do
  55. if Year>=80 then
  56. Year= '19' ||Year
  57. else
  58. Year= '20' ||Year
  59. end
  60. y=Year-0001
  61. b=y*365
  62. b=b+y%4
  63. b=b-y%100
  64. b=b+y%400
  65. m=mm-01
  66. do i=1 to m
  67. b=b+word(DaysInMonth,i)
  68. end
  69. if mm>2 then
  70. do
  71. if 0=Year//4 then
  72. do
  73. if 0=Year//100 then
  74. do
  75. if 0=Year//400 then
  76. b=b+1
  77. end
  78. else
  79. b=b+1
  80. end
  81. end
  82. d=dd-01
  83. b=b+d
  84. return(b)
  85. BD2DATE:Procedure
  86. b=arg(1)
  87. Format=arg(2)
  88. Delimiter=arg(3)
  89. yy=1
  90. n=400
  91. d=n*365
  92. d=d+n/4
  93. d=d-n/100
  94. d=d+n/400
  95. w=b%d
  96. b=b-w*d
  97. yy=yy+w*n
  98. n=100
  99. d=n*365
  100. d=d+n/4
  101. d=d-n/100
  102. w=b%d
  103. b=b-w*d
  104. yy=yy+w*n
  105. n=4
  106. d=n*365
  107. d=d+n/4
  108. w=b%d
  109. b=b-w*d
  110. yy=yy+w*n
  111. n=1
  112. d=n*365
  113. w=b%d
  114. w=min(3,w)
  115. b=b-w*d
  116. yy=yy+w*n
  117. l=0
  118. if 0=yy//4 then
  119. do
  120. if 0=yy//100 then
  121. do
  122. if 0=yy//400 then
  123. l=1
  124. end
  125. else
  126. l=1
  127. end
  128. if l then
  129. p= '31  29  31  30  31  30  31  31  30  31  30  31'
  130. else
  131. p= '31  28  31  30  31  30  31  31  30  31  30  31'
  132. do mm=1 to 12
  133. d=word(p,mm)
  134. if b<d then
  135. leave
  136. b=b-d
  137. end
  138. dd=b+1
  139. yy=right(yy,4, '0')
  140. mm=right(mm,2, '0')
  141. dd=right(dd,2, '0')
  142. if Format= 'DDMMYY' then
  143. return(dd||Delimiter||mm||Delimiter||right(yy,2))
  144. return(yy||Delimiter||mm||Delimiter||dd)
  145. EndBASEDATEXh:
  146. /*
  147. *ADDCOMMA.XH Version 98.090 by Dennis Bareis
  148. *http://www.ozemail.com.au/~dbareis(db0@anz.com)
  149. */
  150. signal EndOfADDCOMMACode
  151. AddCommasToDecimalNumber:procedure
  152. NoComma=strip(arg(1))
  153. if pos(',',NoComma)<>0 then
  154. return(NoComma)
  155. DotPos=pos('.',NoComma)
  156. if DotPos=0 then
  157. AfterDecimal= ''
  158. else
  159. do
  160. if DotPos=1 then
  161. return("0" ||NoComma)
  162. AfterDecimal=substr(NoComma,DotPos+1)
  163. NoComma=left(NoComma,DotPos-1)
  164. end
  165. NoComma=reverse(NoComma)
  166. ResultWithCommas= ""
  167. do while length(NoComma)>3
  168. ResultWithCommas=ResultWithCommas||left(NoComma,3)|| ','
  169. NoComma=substr(NoComma,4)
  170. end
  171. ResultWithCommas=ResultWithCommas||NoComma
  172. ResultWithCommas=reverse(ResultWithCommas)
  173. if AfterDecimal<> '' then
  174. ResultWithCommas=ResultWithCommas|| '.' ||AfterDecimal
  175. return(ResultWithCommas)
  176. EndOfADDCOMMACode:
  177. parse value arg(1)with MaxFileAge FileMasks
  178. if FileMasks= "" then
  179. call SyntaxError 'ERROR: Not enough parameters.', "SyntaxError (too few parms)"
  180. if MaxFileAge<> '-' then
  181. do
  182. if DataType(MaxFileAge, 'Whole Number')=0 then
  183. call SyntaxError 'ERROR: Invalid age of ' || MaxFileAge || '.', "SyntaxError (invalid age)"
  184. end
  185. AddRc=RxFuncAdd('SysFileTree',   'RexxUtil', 'SysFileTree')
  186. AddRc=RxFuncAdd('SysFileDelete', 'RexxUtil', 'SysFileDelete')
  187. TodaysBaseDate=BaseDate()
  188. TotalFiles=0
  189. TotalFilesDeleted=0
  190. TotalFilesDelFailed=0
  191. TotalFutureDated=0
  192. do until FileMasks= ''
  193. parse var FileMasks FileMask FileMasks
  194. if left(FileMask,1)<> '+' then
  195. Subdirs= ''
  196. else
  197. do
  198. Subdirs= 'S'
  199. FileMask=substr(FileMask,2)
  200. end
  201. call SysFileTree FileMask, 'FileName', 'FO' ||Subdirs
  202. TotalFiles=TotalFiles+FileName.0
  203. do i=1 to FileName.0
  204. I2=(FileName.0-i)+1
  205. FullFileName=FileName.I2
  206. if MaxFileAge<> '-' then
  207. do
  208. FileBaseDate=FileBaseDate(FullFileName)
  209. if FileBaseDate<0 then
  210. iterate
  211. FileAge=TodaysBaseDate-FileBaseDate
  212. if FileAge<MaxFileAge then
  213. do
  214. if FileAge<0 then
  215. TotalFutureDated=TotalFutureDated+1
  216. iterate
  217. end
  218. end
  219. if MaxFileAge= '-' then
  220. call charout,'Deleting ' ||FullFileName
  221. else
  222. call charout,Bd2Date(FileBaseDate, 'DDMMYY', '/') || ': Deleting ' || FullFileName || ' (' || FileAge || ' days old)'
  223. DeleteRc=SysFileDelete(FullFileName)
  224. if DeleteRc<>0 then
  225. do
  226. call beep 4500,80
  227. say ' - Failed (DOS RC = ' || DeleteRc || ')'
  228. TotalFilesDelFailed=TotalFilesDelFailed+1
  229. end
  230. else
  231. do
  232. say ''
  233. TotalFilesDeleted=TotalFilesDeleted+1
  234. end
  235. end
  236. end
  237. if(TotalFilesDeleted+TotalFilesDelFailed)<>0 then
  238. say ''
  239. say 'SUMMARY'
  240. say '~~~~~~~'
  241. if TotalFiles=0 then
  242. say 'No files matched the mask!'
  243. else
  244. do
  245. if MaxFileAge<> '-' then
  246. say "Today's Date : " ||date()
  247. say 'Total Files  : ' ||AddCommasToDecimalNumber(TotalFiles)
  248. if TotalFutureDated<>0 then
  249. say 'Future Dated : ' ||AddCommasToDecimalNumber(TotalFutureDated)
  250. say 'Files Deleted: ' ||AddCommasToDecimalNumber(TotalFilesDeleted)
  251. if TotalFilesDelFailed<>0 then
  252. say 'Delete Failed: ' ||AddCommasToDecimalNumber(TotalFilesDelFailed)
  253. end
  254. exit(TotalFilesDelFailed)
  255. SyntaxError:
  256. CmdRc=SIGL
  257. say '[]--------------------------------------------------------------------------[]'
  258. say '| DELOLDER.CMD: Version 98.359, (C)opyright Dennis Bareis 1998               |'
  259. say '|               http://www.labyrinth.net.au/~dbareis/index.htm (db0@anz.com) |'
  260. say '[]--------------------------------------------------------------------------[]'
  261. say ''
  262. say 'This program deletes all files matching the mask if they are of a specified'
  263. say 'minimum age in days.  If you specify an age of "-" then all files matching'
  264. say 'the mask will be deleted.'
  265. say ''
  266. say 'If "+" is specified on  the FileMask then all subdirectories are processed.'
  267. say ''
  268. say 'CORRECT SYNTAX'
  269. say '~~~~~~~~~~~~~~'
  270. say '   DELOLDER[.CMD]  AgeInDays  [+]FileMask1 ...'
  271. say ''
  272. say ''
  273. say arg(1)
  274. exit(CmdRc)
  275.