; Variables used
; $HasSpace Used to determine if branch code < 3 digits
; $Srvah Local machine name
; $FName Current file
; $SFile Source file for copy
; $DFile Destination for copy
; $LogText Used for output to log file
; $LogLoc Central location of log file for current branch
; Date variables
; $yr $mn1 $dy $mn No longer used (need to be cleaned up)
; $sy System date interim value
; $SystemYear Local current year
; $SystemMonth Local current month
; $SystemDay local current day
; $SystemDays Local days value. Used in calc for file age.
; $DateStamp File date
;****** Setup
debug off ; Allows batch debug
break on ; Allows batch to be stopped
;****** Create date filename for logging
$yr=left(@date,4)
$mn1=right(@date,5)
$mn=left($mn1,2)
$dy=right($mn1,2)
@crlf
"Branch Journal File copy to G: Drive"
@crlf
"Do not close this window - It will close when the task is complete"
;****** Set date and create output file
$SY = 1 + left(@date,4) - 1
$SystemYear = 1 + right($SY,2) - 1
$mn1 = 1 + right(@date,5) - 1
$SystemMonth = 1 + left($mn1,2) - 1
$SystemDay= 1 + right(@date,2) - 1
$SystemDays=($SystemYear*365)+($SystemMonth*30.4167)+$SystemDay
;******************************************************************************
;************************************* 022 ************************************
;******************************************************************************
;****** Gets server name from system variable
:GetServer
$Srvah = "HO-022"
;****** Server Selected
:SSel
shell "cmd.exe /c dir f:\JRN022 > f:\JRN022\files.txt"
Open(3, "f:\JRN022\filemove.log", 4)
Open(4, "f:\JRN022\files.txt", 2)
;****** Gets filename and gets age in days
:GetFile
$f = ReadLine(4)
if instr ($f,"free")
goto TheEnd
else
if right($f,4) > ".jnl" or right($f,4) < ".jnl"
goto GetFile
else
$Fname=Right($f,12)
$LogText=$Fname
$DateStamp=left($f,8)
$LogText=$LogText+$DateStamp
;****** +1 -1 in this section is to create a numeric variable
$FileYear = 1 + right($DateStamp,2) - 1
$LogText=$LogText+" "+$FileYear
$mn2 = right($DateStamp,5)
$LogText=$LogText+" "+$mn2
$FileMonth = 1+ left($DateStamp,2) - 1
$LogText=$LogText+" "+$FileMonth
$FileDay= 1 + left($mn2,2) - 1
$LogText=$LogText+" "+$FileDay
$FileDays=($FileYear*365)+($FileMonth*30.4167)+$FileDay
$LogText=$LogText+" "+$FileDays
$FileAge=$SystemDays-$FileDays
$LogText=$LogText+" "+$FileAge
;****** Establish if file move is needed
;****** This routine will IGNORE files that match the specified criteria
if $FileAge < 30
goto GetFile
Else
;****** Analyse FileName
$FDay1 = right($Fname,6)
$FDay = left($FDay1,2)
$FMonth1 = right($Fname,7)
$FMonth = left($FMonth1,1)
$FYear1 = right($Fname,9)
$FYear = left($FYear1,2)
;****** Convert month letter to Month name
;****** Added 01, 02 etc to month name to sort directories.
:Month
if instr ($FMonth,"A") > 0
$FMonth = "01-January"
goto FileN
endif
if instr ($FMonth,"B") > 0
$FMonth = "02-February"
goto FileN
endif
if instr ($FMonth,"C") > 0
$FMonth = "03-March"
goto FileN
endif
if instr ($FMonth,"D") > 0
$FMonth = "04-April"
goto FileN
endif
if instr ($FMonth,"E") > 0
$FMonth = "05-May"
goto FileN
endif
if instr ($FMonth,"F") > 0
$FMonth = "06-June"
goto FileN
endif
if instr ($FMonth,"G") > 0
$FMonth = "07-July"
goto FileN
endif
if instr ($FMonth,"H") > 0
$FMonth = "08-August"
goto FileN
endif
if instr ($FMonth,"I") > 0
$FMonth = "09-September"
goto FileN
endif
if instr ($FMonth,"J") > 0
$FMonth = "10-October"
goto FileN
endif
if instr ($FMonth,"K") > 0
$FMonth = "11-November"
goto FileN
endif
if instr ($FMonth,"L") > 0
$FMonth = "12-December"
goto FileN
endif
$FMonth = "All"
; ***** Make directory and copy for old files
$FilePath = "g:\Journal\"+$Srvah+"\PreFeb2000"
; ***** If filenames are less than 12 (8.3) characters then remove the blank characters
; ***** This is used for files older than feb2000
:DirExist
If exist ($FilePath)
goto CpyFile
else md $FilePath
endif
goto CpyFile
:FileN
$HasSpace = instr ($FName," ")
if $HasSpace = 0
goto MakDir
else
$Fname=right($FName,(12-$HasSpace))
endif
:MakDir
$FilePath = "g:\Journal\"+$Srvah+"\20"+$FYear+"\"+$FMonth
If exist ($FilePath)
goto CpyFile
else
md $FilePath
endif
; ***** Copy file
:CpyFile
$SFile="f:\JRN200\"+$Fname
$DFile=$FilePath+"\"+$Fname
$LogText=$LogText+" "+$DFile
copy $SFile $DFile
if exist ($DFile)
goto GoodCopy
else
:BadCopy
$LogText=$LogText+" COPY FAILED"+@crlf
writeline(3,$LogText)
goto GetFile
endif
:GoodCopy
$LogText=$LogText+" copied"
del $SFile
If exist ($SFile)
goto NoDelete
else
$LogText=$LogText+" and deleted"+@crlf
writeline(3,$LogText)
goto GetFile
endif
:NoDelete
$LogText=$LogText+" but not deleted"+@crlf
writeline(3,$LogText)
goto GetFile
; ***** Program end and clean up
:TheEnd
; close open files
close (3)
close (4)
; make copy of log file on central area
$LogLoc="g:\journal\"+$Srvah+"\FileMove.log"
del $LogLoc
copy f:JRN200\FileMove.log $LogLoc
del f:\JRN200\files.txt