I hate posting so much on one subject but:

The script has a subroutine "delroutine" because Kix doesn't support loop's withing loops...
It will end with the error "Loop without while" - try to find that in a hurry!
Anyone even trip over that one yet? hehe..


run the script from the root of your dir-structure:

BREAK ON

DIM $dirarray[4] ;sorry for the similarity to the word diarriah *grin*
$dirarray[0]="\directory"
$dirarray[1]="\directory1"
$dirarray[2]="\directory2"
$dirarray[3]="\directory3"

$countermax=4 ;(total array + 1)

$counter=0
WHILE $counter<$countermax
SHELL '%comspec% /c dir /b $dirarray[$counter] >> $dirarray[$counter].txt'
$counter=$counter+1
LOOP

$counter=0
WHILE $counter<$countermax
GOSUB delroutine
$counter=$counter+1
LOOP


;------------------------DELROUTINE---------------------
:delroutine
OPEN (6,"$dirarray[$counter].txt")

$currentfile=READLINE(6)
WHILE ($currentfile<>"")
$monthover=0

$date_old=getfiletime("$currentfile")
$year_old=VAL(substr($date_old,1,4))
$month_old=VAL(substr($date_old,6,2))
$day_old=VAL(substr($date_old,9,2))

IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old<12) $monthover=1 GOTO decided ENDIF
IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old=12) AND (@monthno>1) $monthover=1 GOTO decided ENDIF
IF ((@monthno-$month_old)>1) $monthover=1 GOTO decided ENDIF
IF ((@monthno-$month_old)=1) $monthover=1 GOTO decided ENDIF ;see comment below
GOTO endloop

:decided
DEL "\$dirarray[$counter]\$currentfile"
:endloop
$currentfile=READLINE(6)
LOOP

CLOSE (6)
DEL "$dirarray[$counter].txt" ;delete the directory-content-file when done.
RETURN
;-------------------------------------------------------------


It looks like the script will delete all files of the previous month as soon as a new
month is reached, but if you schedule the script to run evey 28'th day of the month
it would only delete files created the month before.