BREAK ON CLS
;***********************************************************************
;* Set some variables
;***********************************************************************; * This is where the temporary filelist and the logfile are placed.
; * (Preferably on the local hard-disk (Need for speed
)
$WorkDir="E:\scripts\remove"
;* These are the directories that need to be cleaned up.
DIM $RemoveDir[10]
$RemoveDir[0]="E:\scripts\remove\test"
$RemoveDir[1]="E:\scripts\remove\test2"
; * Delete files if they are older than the current date minus these days.
$days=30
;***********************************************************************
;* Create a Logfile.
;***********************************************************************
$lognr=0
while exist("$workdir\log$lognr.txt") $lognr=$lognr+1 loop
$nul=open (2,"$workdir\log$lognr.txt",5)
;***********************************************************************
;* Find the date (minus $days)
;***********************************************************************
$CurY=@YEAR $CurM=@MONTHNO $CurD=@MDAYNO
if $CurM < 3 $CurM = $CurM + 12 $CurY = $CurY - 1 endif
$CurInt = $CurD + ( 153 * $CurM - 457 ) / 5 + 365 * $CurY + $CurY / 4 - $CurY / 100 + $CurY / 400 - 306
$MyZ=$CurInt - $days + 306 $MyH=100*$MyZ-25 $MyA=$MyH/3652425 $MyB=$MyA-$MyA/4
$rd_year=(100*$MyB+$MyH)/36525 $MyC=$MyB+$MyZ-365*$rd_year-$rd_year/4
$rd_month=(5*$MyC+456)/153 $rd_day=$MyC-(153*$rd_month-457)/5
if $rd_month > 12 $rd_year=$rd_year + 1 $rd_month = $rd_month - 12 endif
if len("$rd_month")=1 $rd_month="0"+"$rd_month" endif
if len("$rd_day")=1 $rd_day="0"+"$rd_day" endif
$CompareDate="$rd_year/$rd_month/$rd_day"
;***********************************************************************
;* Generate a textfile with all filenames (again for each directory)
;***********************************************************************
$dirnr=0
while $removedir[$dirnr]>""
$nul=close(1)
del "$workDir\files.txt"
$Remdir=$removedir[$dirnr]
shell "%comspec% /c dir $Remdir /s/b > $workdir\files.txt"
$nul=open (1,"$workdir\files.txt")
gosub main_loop
$dirnr=$dirnr+1
loop
;***********************************************************************
;* The End.
;***********************************************************************
EXIT
;***********************************************************************
;* Subroutine: Mainloop comparing dates.
;***********************************************************************
:main_loop
$line=readline(1)
while @ERROR=0
gosub do_line
$line=readline(1)
loop
return
;***********************************************************************
;* Sub-subroutine: Delete $line and write a line to the Log-file.
;***********************************************************************
:do_line
$time=getfiletime($line)
if $time>""
if substr($time,1,10)<$CompareDate
$nul=writeline(2,$line+", Filetime = $time, Removed on @DATE @TIME"+chr(13)+chr(10))
del $line
endif
endif
return