Break ON ; Allows batch to be stopped
$=SetOption("Explicit","ON")
Dim $sSRVAH $sSRVAH="HO-022"
Dim $iArchiveDays $iArchiveDays=30
Dim $iSourceDir $sSourceDir="F:\JRN022\"
Dim $sTargetDir $sTargetDir="G:\Journal\"+$sSRVAH+"\"
Dim $sLogFile $sLogFile=$sSourceDir+"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 G: 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($sSourceDir+"*.jnl")
While Not @ERROR
$sFileDate=Split(GetFileTime($sSourceDir+$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 $sSourceDir+$sFile $sArchivePath
If @ERROR
$=Writeline($fhLog," FAILED with error ["+@ERROR+"] "+@SERROR+@CRLF)
Else
$=WriteLine($fhLog," Moved OK"+@CRLF)
EndIf
EndIf
$sFile=Dir()Split(GetFileTime($sSourceDir+$sFile))[0]
Loop
$=Close($fhLog)
Move $sLogFile $sTargetDir
Exit 0
; *********************** PAY NO ATTENTION TO THE MAN BEHIND THE CURTAIN ********************************
;
;FUNCTION SerialDate
;
;ACTION Convert dates to numbers (and back) for the purpose of performing date math
;
;AUTHOR ScriptLogic (http://www.scriptlogic.com)
;
;CONTRIBUTOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.1
;
;SYNTAX SERIALDATE(DATE)
;
;PARAMETERS DATE or NUMBER
; if a date is used, it must be in the form of "YYYY/MM/DD"
; if a number is used, it must be a number previously derived from this function.
;
;RETURNS If a date is passed to this function, the function returns a number. If a number is
; passed to this function, a date "YYYY/MM/DD" is returned
;
;REMARKS This function was developed as a core routine for the DateMath( ) function. In
; normal usage, you would most like just use the DateMath( ) function which depends
; on this function.
; Algorithms used in the development of this routine were obtained from:
; http://www.capecod.net/~pbaum/date/date0.htm
;
; Fixed a couple of inconsistencies in the returned values and formatting
;
; Original UDF is posted at http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=SerialDate
;
;DEPENDENCIES none
;
;EXAMPLE $rc=serialdate('2001/07/01')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000089
;
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