7 Replies Latest reply: Jul 7, 2016 2:43 PM by Onno van Knotsenburg RSS

    Load latest file - filetype can be either .txt or .csv

    Jamel Oueslati

      Hi all,

       

      I have a script which will load the latest file in a stated folder.   Currently it is the latest .CSV but sometimes a .txt file is saved.....

       

      I need help on what changes is required in my load script, to now take into account the .txt files.  So basically I require to load the latest file, no matter what file extension it has.

       

      This is my current code:

       


      
      

      If FileSize('F:\file_location\*.csv')>0 then
      for each File in filelist ('F:\file_location\*.csv')
      Folder:
      Load '$(File)' as Name,
      FileTime( '$(File)' ) as FileTime
      autogenerate 1;
      next File

      LatestFile:
      first 1
      Load
      Name,
      FileTime,
      1
      as dummy
      Resident Folder
      Order By FileTime DESC;
      drop table Folder;

      LOAD [@1:n] as 'Image Data'
      FROM
      '$(File)'
      (
      fix, utf8, no labels);
      ELSE 

      Temp:
      Load MsgBox ('No files found in the folder!','Status','OKCANCEL','ICONHAND') AutoGenerate 1;
      DROP Table Temp;
      ENDIF