Ok!

Thanks DrillSergeant! Not only have we now a fully functional "delete-files-older-than" script, we also know how to use it the way we want to! I publish the final version below...

code:

;======================================================================
;=== DESCRIPTION: Script to delete files older than '$days' old.
;=== AUTHOR: DrillSergeant / additions by Masken
;=== DATE: 2001-01-15
;=== FILENAME: delfiles.kix
;=== PURPOSE: Automated deletion of specified files in specified
;=== folders.
;=== REVISIONS: Rev 0: Initial release
;======================================================================

BREAK ON
CLS
;======================================================================
;=== Set varables. $WorkDir specifies where the logfile, and temporary
;=== files should be placed (prefferably on a local HD, for speed. In
;=== this case a hidden share on a server is specified).
;=== $RemoveDir is the list with directories in which the script looks
;=== for files.
;=== The smallest value for the $RemoveDir[] array is 3. Always
;=== specify an extra varable for the array (where array ranges from
;=== 0 to x +1), to get the script working properly.
;=== Files older than today's date minus $Days will be deleted.

$WorkDir = "\\[server]\del_log$$"
DIM $RemoveDir[3]
$RemoveDir[0] = "D:\AS400\In"
$RemoveDir[1] = "D:\AS400\Out"
$Days = 90


;======================================================================
;=== Create a logfile on a central server (the number of the logfile is
;=== incremented if a logfile for the same workstation already exists
;=== in the $WorkDir).
;=== Here @WKSTA is used to generate the log's filename for each
;=== workstation.

$LogNr = 0
WHILE EXIST("$WorkDir\@WKSTA_log$LogNr.txt")
$LogNr = $LogNr + 1
LOOP
$nul = OPEN(2,"$WorkDir\@WKSTA_log$LogNr.txt",5)


;======================================================================
;=== Calculate 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"


;======================================================================
;=== Here you control whether files in subdirectories should be
;=== or excluded, with the switch "/s". The "/b" switch stands for
;=== "base notation", (which excludes everything but the filename),
;=== don't change this one!

$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 that reads lines. Goes down into the
;=== sub-subroutine to compare dates between today and the file.

:MAIN_LOOP
$line = readline(1)
WHILE @ERROR=0
GOSUB DO_LINE
$line = readline(1)
LOOP
RETURN


;======================================================================
;=== Sub-Subrutin: Compares the dates in files.txt with the calculated
;=== date. If file should be deleted, add to log and delete.

O_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


_________________________
The tart is out there