Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

For Loop to store all related files

Hi. I am trying to run this statement for all the .txt files available in the directory. I tried using a For loop but it only picked up the 1st .txt file available in the directory. Appreciate help from you guys out there...

for each Ext in 'txt'

for each FileName in ('$(sPathResources)'&'\*.' &Ext)

File:
LOAD *

FROM [$(FileName)]
(txt, codepage is 1252, embedded labels, delimiter is spaces);


STORE File INTO $(FileName).qvd (qvd);

DROP Table File;

NEXT FileName

NEXT Ext

p/s: sPathResources = path where files are stored.

1 Solution

Accepted Solutions
jeffmartins
Partner - Creator II
Partner - Creator II

Hi erin wan,

Try to use this code

for each File in FileList('$(sPathResources)\*.txt')

          File:

          LOAD *, FileBaseName() as FileName

          FROM [$(File)]

          (txt, codepage is 1252, embedded labels, delimiter is spaces);

          let vFileName = FieldValue('FileName', 1);

          drop field FileName;

          STORE File INTO $(sPathResources)\$(vFileName).qvd (qvd);

          DROP Table File;

NEXT File

Regards

View solution in original post

4 Replies
jeffmartins
Partner - Creator II
Partner - Creator II

Hi erin wan,

Try to use this code

for each File in FileList('$(sPathResources)\*.txt')

          File:

          LOAD *, FileBaseName() as FileName

          FROM [$(File)]

          (txt, codepage is 1252, embedded labels, delimiter is spaces);

          let vFileName = FieldValue('FileName', 1);

          drop field FileName;

          STORE File INTO $(sPathResources)\$(vFileName).qvd (qvd);

          DROP Table File;

NEXT File

Regards

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You are missing the FileList keyword.

for each FileName in FileList('$(sPathResources)'&'\*.' & Ext)

-Rob

Not applicable
Author

Thanks jeffmartins! It works

Not applicable
Author

Thanks Rob