Question

Is there a way for me to limit my array by the date of the file? I am wanting all the files from the drive but only if the date on the file is > the last stored import datetime. When I build the array on "asterisk.asterisk" it takes too long. Any thoughts?

fsLAST = ''
USE CMEMAILS IN 0 
SELECT CMEMAILS 
SET ORDER TO DTSTAMP    && DTSTAMP
GO BOTTOM
fsLAST = CMEMAILS.DTSTAMP
local array MyFiles[1,5]
        nFilesFound = ADIR( MyFiles, ALLTRIM(cmcontrol.cpath) + '*.*')

    for i = 1 to nFilesFound
        SELECT cmemails
    DO CASE
    CASE DATETIME(YEAR(MyFiles[ i, 3]), MONTH(MyFiles[ i, 3]), DAY(MyFiles[ i, 3]), VAL(LEFT(MyFiles[ i, 4], 2)), VAL(SUBS(MyFiles[ i, 4], 4, 2)), VAL(SUBS(MyFiles[ i, 4],7,2))) > fsLAST
            insert into cmemails (cprimary, csubject, ddate, dtime, cattribs, dtstamp) values ;
            (generateGuid(26), MyFiles[ i, 1], MyFiles[ i, 3], MyFiles[ i, 4], MyFiles[ i, 5],DATETIME(YEAR(MyFiles[ i, 3]), MONTH(MyFiles[ i, 3]), DAY(MyFiles[ i, 3]), VAL(LEFT(MyFiles[ i, 4], 2)), VAL(SUBS(MyFiles[ i, 4], 4, 2)), VAL(SUBS(MyFiles[ i, 4],7,2))) )
    ENDCASE
endfor
Was it helpful?

Solution

since the array has element 3 as the date and 4 as the time, you could do..

for i = ...
   ltFileTime = CTOT( DTOC( MyFiles[1,3] ) + " " + MyFiles[1,4] )
   if ltFileTime > fsLast
     */ do your insert...

   endif 
endfor

you might need to make sure

SET CENTURY ON

to ensure proper date/time conversion.

You can also use the ltFileTime instead of your DATETIME(year,month,date,etc) for readability...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top