; read the first directory entry
$sFile=Dir($iSourceDir+"*.jnl")
; Loop until an error occurs (no more files)
While Not @ERROR
; get the file timestamp, and split off the date portion only
$sFileDate=Split(GetFileTime($iSourceDir+$sFile))[0]
; Calculate the difference between today and the file timestamp
$iFileAge=CInt(SerialDate(@DATE))-SerialDate($sFileDate)
; If the age is more than the archive limit, process it
If $iFileAge > $iArchiveDays
; get the character that represents the month
$iMonthIndex=InStr($sMonthLetters,SubStr($sFile,6,1)
; Not too sure about this.. results in "20" plus the 4th and 5th chars of the file name?
; Do any files date back to before 2000?
$sFileYear="20"+SubStr($sFile,4,2)
; Define the path where the file will be archived
; path is $sTargetDir + $sFileYear defined above, then a 2-digit month number, a dash, and finally the month-name
$sArchivePath=$sTargetDir+$sFileYear+"\"+Right("0"+$iMonthIndex,2)+"-"+$asMonths[$iMonthIndex]
'DEBUG - Archive Path:' ?
$sArchivePath ?
; log the action
$=WriteLine($fhLog,"Archiving "+$sFile+" to "+$sArchivePath+@CRLF)
; create the archive path if it doesn't exist
If Not Exist($sArchivePath) MD $sArchivePath EndIf
; move the file to the archive folder and log success or failure
Move $iSourceDir+$sFile $sArchivePath
If @ERROR
$=Writeline($fhLog," FAILED with error ["+@ERROR+"] "+@SERROR+@CRLF)
Else
$=WriteLine($fhLog," Moved OK"+@CRLF)
EndIf
EndIf
; get the next file from the directory
$sFile=Dir()
Loop