11 Replies Latest reply: Dec 18, 2015 6:35 AM by Marcus Sommer RSS

    Only load latest file

    Deborah Pyykkonen

      I am using the script below for incremental loading of files copied out to a shared drive and it works great.


      I want to change this code to only load the latest file for another application I am working on.  Any suggestions how I can determine which file is the most recent?  I did not write this code, I got this from the community some time back.


      //Creates current table  of excel files in the directory for incremental loading to compare to existing

      TRACE DoDir;

      SUB DoDir (Root) 

           FOR Each File in FileList(Root&'$(vSourceFile)') 


           LOAD '$(File)' as File_Name

           AutoGenerate 1; 

         NEXT File 




      CALL DoDir (vRoot) 

      Trace Loop;

      FOR i=0 to NoOfRows('Files')-1  

         LET vFileName = Peek('File_Name', 0, 'Files'); 

         IF Date(Date#(SubField(vFileName, '_', 4), 'DD-MMM-YYYY')) >= vDateFrom and Date(Date#(SubField(vFileName, '_', 5), 'DD-MMM-YYYY')) <= vDateTo then 


            LOAD * 

            From [$(vRoot)\$(vFileName)] ; 


      NEXT i;