$home = "K:\"
;$home = "c:\Reports\"
$setup = "\\server1\folder1\folder2\setup3.txt"
$source = "\\server2\folder21\folder22\folder23\folder24\"
;open txt file with file and folder names
IF Open(1, "$setup") = 0
$drfile = ReadLine(1)
ELSE
BEEP
? "setup3 file not opened, error code: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
$thismo = @monthno -2
IF $thismo = 0
$month = "11"
ELSE
IF $thismo > 9
$month = CSTR($thismo)
ELSE
$month = "0" + CSTR($thismo)
ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR -1, @YEAR)
;open log file
IF Open(2, "\\server1\folder1\folder2\log$month.txt",5) = 0
$w = WriteLine( 2 , "rpts3.kix started at " +@DATE + @TIME + Chr(13) + Chr(10) )
ELSE
BEEP
? "Error opening log file: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
;main program loop
WHILE $readerr = 0
$x = ReadLine(1)
$readerr = @ERROR
$file = SUBSTR($x, 1, INSTR($x, ",")-1)
$x = SUBSTR($x, INSTR($x, ",")+1, LEN($x) - INSTR($x, ","))
$directory = SUBSTR($x, 1, INSTR($x, ",")-1)
$x = SUBSTR($x, INSTR($x, ",")+1, LEN($x) - INSTR($x, ","))
$folder = SUBSTR($x, 1, LEN($x) - INSTR($x, ","))
;MD "$home$directory$folder\$year-$month"
sleep 1
IF Exist("$source$file.pdf")
IF $folder <> ""
copy "$source$file.pdf" "$home$directory$folder\$year-$month\$file.pdf"
ENDIF
ENDIF
LOOP
$w = WriteLine( 2 , "rpts3.kix finished at " +@DATE + @TIME + Chr(13) + Chr(10) )
$ = Close (1)
$ = Close (2)