Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
Hello Michael,
as far as I understand you I would try a "for each in filelist" instead of a for-loop (similar to the code below):
for each File in filelist ([\\PATH\datafiles\*.csv]) // or [\\PATH\datafiles\MyFile_*.csv]
LOAD
*
From
$(File) (txt, codepage is 1252, no labels, delimiter is '\t', msq);
Regards, Roland
Hello Michael,
as far as I understand you I would try a "for each in filelist" instead of a for-loop (similar to the code below):
for each File in filelist ([\\PATH\datafiles\*.csv]) // or [\\PATH\datafiles\MyFile_*.csv]
LOAD
*
From
$(File) (txt, codepage is 1252, no labels, delimiter is '\t', msq);
Regards, Roland
Michael,
I'm sure that the simpler way will work, no need for the FileName varable:
LOAD
...
FROM \\PATH\datafiles\MyFile_$(a).csv ...
Yes, even simpler from Ronald