Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Announcing the newest addition to the Qlik Community, Qlik Gallery! Learn More
Highlighted
markgraham123
Valued Contributor

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

Re: load files with specific names from folder through for loop

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

30 Replies
MVP & Luminary
MVP & Luminary

Re: load files with specific names from folder through for loop

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

-Rob

Re: load files with specific names from folder through for loop

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

Re: load files with specific names from folder through for loop

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
Valued Contributor

Re: load files with specific names from folder through for loop

Rob,

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

Re: load files with specific names from folder through for loop

So for you, may be this:

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

      Table1:

      LOAD *

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

NEXT

markgraham123
Valued Contributor

Re: load files with specific names from folder through for loop

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.

Re: load files with specific names from folder through for loop

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
Valued Contributor

Re: load files with specific names from folder through for loop

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

Re: load files with specific names from folder through for loop

Is this a list or a single date?