Break ON ; Allows batch to be stopped
$=SetOption("Explicit","ON")
Dim $sSRVAH $sSRVAH="HO-022"
Dim $iArchiveDays $iArchiveDays=30
Dim $iSourceDir $iSourceDir="F:\Journal\HO-022\"
Dim $sTargetDir $sTargetDir="F:\Journal\Archive"+$sSRVAH+"\"
Dim $sLogFile $sLogFile=$iSourceDir+"FileMove.log"
Dim $sArchivePath
Dim $sFile
Dim $sFileDate
Dim $sFileYear
Dim $iFileAge
Dim $iMonthIndex
Dim $sMonthLetters $sMonthLetters="ABCDEFGHIJKL"
Dim $asMonths $asMonths=Split("ALL January February March April May June July August September October November December")
Dim $fhLog $fhLog=FreeFileHandle()
"Branch Journal File copy to F: Drive"+@CRLF
"Do not close this window - It will close when the task is complete"+@CRLF
If Open($fhLog,$sLogFile,4+1)
"ERROR: Cannot open log file for writing, reason: ["+@ERROR+"] "+@SERROR+@CRLF
"Aborting."+@CRLF
Exit @ERROR
EndIf
$sFile=Dir($iSourceDir+"*.jnl")
While Not @ERROR
$sFileDate=Split(GetFileTime($iSourceDir+$sFile))[0]
$iFileAge=CInt(SerialDate(@DATE))-SerialDate($sFileDate)
If $iFileAge > $iArchiveDays
$iMonthIndex=InStr($sMonthLetters,SubStr($sFile,6,1)
$sFileYear="20"+SubStr($sFile,4,2)
$sArchivePath=$sTargetDir+$sFileYear+"\"+Right("0"+$iMonthIndex,2)+"-"+$asMonths[$iMonthIndex]
$=WriteLine($fhLog,"Archiving "+$sFile+" to "+$sArchivePath+@CRLF)
If Not Exist($sArchivePath) MD $sArchivePath EndIf
Move $iSourceDir+$sFile $sArchivePath
If @ERROR
$=Writeline($fhLog," FAILED with error ["+@ERROR+"] "+@SERROR+@CRLF)
Else
$=WriteLine($fhLog," Moved OK"+@CRLF)
EndIf
EndIf
$sFile=Dir()Split(GetFileTime($iSourceDir+$sFile))[0]
Loop
$=Close($fhLog)
Move $sLogFile $sTargetDir
Exit 0
function serialdate($ExpD)
dim $z,$h,$a,$b,$c,$y,$m,$d
if instr($ExpD,'/')
$ExpD=split($ExpD,'/')
$y=val($ExpD[0])
$m=val($ExpD[1])
$d=val($ExpD[2])
if $m<3
$m=$m+12
$y=$y-1
endif
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
if $m>12
$y=$y+1
$m=$m-12
endif
$SerialDate=right('0000'+$y,4)+'/'+right('00'+$m,2)+'/'+right('00'+$d,2)
endif
endfunction