Qlik Community

QlikView Deployment

Discussion Board for collaboration related to QlikView Deployment.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

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

1 Solution

Accepted Solutions
Not applicable

AW:Loop read in using sequential filenames

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

3 Replies
Not applicable

AW:Loop read in using sequential filenames

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

mov
Esteemed Contributor III

Loop read in using sequential filenames

Michael,
I'm sure that the simpler way will work, no need for the FileName varable:
LOAD
...
FROM \\PATH\datafiles\MyFile_$(a).csv ...

mov
Esteemed Contributor III

AW:Loop read in using sequential filenames

Yes, even simpler from Ronald

Community Browser