PRIVATE LCDATAPATH,LCPERIOD
STORE '' TO LCDATAPATH
STORE '' TO LCPERIOD

CLOSE DATABASES all

IF ! FILE('COMPANYYEAR.DBF')
	DO CREATE_DBF
ENDIF

LCDATAPATH = (MPROG_PATH) + '\DATA' + '\01'
IF DIRECTORY(LCDATAPATH) = .F.
	MD (LCDATAPATH)
	DO CREATE_COMPANYDBF
ENDIF

CLOSE DATABASES all

USE (MPROG_PATH) + '\COMPANYYEAR' IN 0
SELECT COMPANYYEAR
GO TOP
SCAN
	PRIVATE LNCUR_REC,LCLOCALPATH
	LNCUR_REC = RECNO('COMPANYYEAR')

*	LCDATAPATH = (MPROG_PATH) + '\DATA' + '\01\' + ALLTRIM(LCPERIOD)

	LCPERIOD = ALLTRIM(STR(YEAR(START_DT))) + ALLTRIM(STR(YEAR(END_DT)))
	LCLOCALPATH = SYS(5) + (MPROG_PATH) + 'DATA\' + ALLTRIM(LCPERIOD)
	
	LCDATAPATH = (MPROG_PATH) + '\DATA' + '\01'

	MESSAGEBOX(LCDATAPATH)
	MESSAGEBOX(LCLOCALPATH)

	CD (LCDATAPATH)
	
	SET STEP ON 
	
	ON KEY
	ACTIVATE WINDOW COMMAND
	SUSPEND 	


lnnoffiles = ADIR(filearray,'*.*')
FOR i = 1 TO lnnoffiles 
	lcsourcefile = lcsource + filearray(i,1)
	lcdestinationfile = lcdestination + filearray(i,1)
	WAIT WINDOW 'Creating file : ' + lcdestinationfile NOWAIT 
	COPY FILE lcsourcefile TO lcdestinationfile
ENDFOR 

*	IF DIRECTORY(LCDATAPATH) = .F.
*		MD (LCDATAPATH)
*	ENDIF
*	DO CREATE_NEW_YEAR WITH LCDATAPATH,LCPERIOD
	
	SELECT COMPANYYEAR
	GO (LNCUR_REC)
ENDSCAN 	


PROCEDURE CREATE_DBF

USE (MPROG_PATH) + '\COMPANYYEARSTRU' IN 0
SELECT COMPANYYEARSTRU
COPY STRUCTURE TO (MPROG_PATH) + "\COMPANYYEAR" WITH CDX
USE IN COMPANYYEARSTRU
CLOSE DATABASES ALL


PROCEDURE CREATE_COMPANYDBF

USE (MPROG_PATH) + '\COMPANYYEAR' IN 0

USE (MPROG_PATH) + "\YEARLIST" IN 0
USE (MPROG_PATH) + "\AUTOPARA" IN 0

SELECT AUTOPARA
SCATTER MEMVAR 
SELECT YEARLIST
GO TOP
SCAN
	INSERT INTO COMPANYYEAR FROM MEMVAR

	SELECT COMPANYYEAR
	REPLACE COMPANY_NO WITH '01'
	REPLACE START_DT WITH YEARLIST.START_DT
	REPLACE END_DT WITH YEARLIST.END_DT
*	REPLACE PERIOD WITH YEARLIST.PERIOD
	REPLACE EOY_FLG WITH YEARLIST.EOY_FLG
	REPLACE TRADE_FLG WITH YEARLIST.TRADE_FLG
	REPLACE P_L_FLG WITH YEARLIST.P_L_FLG
	REPLACE PROFIT_FLG WITH YEARLIST.PROFIT_FLG
	REPLACE DEPRI_FLG WITH YEARLIST.DEPRI_FLG
	REPLACE YEAR_COD WITH YEARLIST.YEAR_COD
*	REPLACE HIDE_FLG WITH YEARLIST.HIDE_FLG
	REPLACE VERSION WITH YEARLIST.VERSION

ENDSCAN


*!*	PROCEDURE CREATE_NEW_YEAR

*!*	PARAMETERS PCDATAPATH,PCPERIOD

*!*	PRIVATE LCCURPTH

*!*	LCCURPTH = ''
*!*	CD (PCDATAPATH)
*!*	LCCURPTH = SYS(5) + (MPROG_PATH) + 'DATA\' + ALLTRIM(PCPERIOD) + '\*.*'
*!*	RUN COPY &LCCURPTH

