Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
markgraham123
Specialist
Specialist

load files with specific names from folder through for loop

Hi all,

I'm trying to load 5 files from the folder of 1000 files.

I have stored file names in vFilenames.

vFilenames = abg, dhjk, qwe, qwee, gsdf;

How can i load only these 5 files from the folder, instead of loading all files and then filtering by the filebasename()?

FOR EACH File in FileList('$(vFolder)\$(vFilenames).QVD')  //Storing filenames in the variable 'File'  

      Table1:

      LOAD *

  FROM [$(File)] (qvd);

NEXT

The above is not working.

Any help is highly appreciated.

1 Solution

Accepted Solutions
sunny_talwar

Remove the Concat and then try this

LET NumRows=FieldValueCount('%DateKey');

SET vFolder = '\\Folder\';

FOR i=1 to $(NumRows)

LET vFile = FieldValue('%DateKey', $(i));

    Table1:

          LOAD *

    FROM [$(vFolder)\$(vFile).qvd] (qvd);

NEXT

View solution in original post

30 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

What do you mean, not working? Script Error? Can you post the expanded load statement from the document log and the error message?

-Rob

sunny_talwar

Look at the first example here:

https://help.qlik.com/en-US/sense/3.1/Subsystems/Hub/Content/Scripting/ScriptControlStatements/For%2...


// LOAD the files 1.csv, 3.csv, 7.csv and xyz.csv

for each a in 1,3,7,'xyz'


     LOAD *

     from file$(a).csv;


next

sunny_talwar

I think Rob, the issue is that vFilenames expand to this:

FOR EACH File in FileList('$(vFolder)\abg, dhjk, qwe, qwee, gsdf.QVD')  //Storing filenames in the variable 'File' 

      Table1:

      LOAD *

  FROM [$(File)] (qvd);

NEXT

Which is not what he wants, I believe

markgraham123
Specialist
Specialist
Author

Rob,

The filename were not being read / the file names have to be expanded individually.

sunny_talwar

So for you, may be this:

FOR EACH File in 'abg', 'dhjk', 'qwe', 'qwee', 'gsdf'

      Table1:

      LOAD *

  FROM [$(vFolder)\$(File).qvd] (qvd);

NEXT

markgraham123
Specialist
Specialist
Author

Sunny,

Do we have to hard code the file names?

I was trying to store file names in variable.

As the file names keep changing.

sunny_talwar

Not tested, but may be like this:

SET vFilenames = 'abg', 'dhjk', 'qwe', 'qwee', 'gsdf';


FOR EACH File in $(vFilenames)

      Table1:

      LOAD *

  FROM [$(vFolder)\$(File).qvd] (qvd);

NEXT

markgraham123
Specialist
Specialist
Author

Sunny,

It is not working:

LET vFilelist = peek('DateKey');  //I'm readin this from another table. This has the dynamic list of file names

SET vFolder = '\\Folder\';

FOR EACH File in $(vFilelist)

      Table1:

      LOAD *

  FROM [$(vFolder)\$(File).qvd] (qvd);

NEXT

The file names are not getting read by the script in the for loop

sunny_talwar

Is this a list or a single date?