3 Replies Latest reply: Mar 30, 2011 2:54 PM by Michael Solomovich RSS

    Loop read in using sequential filenames

      Team,

       

      I am attempting to create an automatic load which will count the number of files in a folder and then read in each of those files using a FOR/NEXT loop, and sequential filenames (eg. MyFile_1, MyFile_2, etc...).

      There is one section of the code that does appear to work. The count of the filenames returns the correct value for "n", however the line of code struck out below in which I attempt to set a macro equal to the value of the field "n" will not work (this is needed so that I can end my loop at $(N) which would equal the final "MyFile_x").

      If anyone can provide any insight on how I can accomplish that goal it would be greatly appreciated.

       

       

      LET N=0;

      filenames:

      load

      Filename() as filename

      FROM

      [\\PATH\datafiles\*.csv]

      ;

      load count(DISTINCT(filename)) as n

      resident filenames;

      load n,

      $(N)=sum(n)

      resident [filenames-1];

       

      FOR a = 2 to $(N);

       

      Let FileName = [\\PATH\datafiles\MyFile_$(a).csv]'; // FileName is a variable representing the csv file name aka MyFile_1

       

      fact_Pre:

      Load

      *

      FROM

      $(FileName)

      (txt, codepage is 1252, embedded labels, delimiter is ',', msq);

       

      Next



       

      Thank you,

      Michael