Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

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

Re: For Loop to store all related files

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

4 Replies
jeffmartins
Contributor II

Re: For Loop to store all related files

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

Re: For Loop to store all related files

You are missing the FileList keyword.

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

-Rob

Not applicable

Re: For Loop to store all related files

Thanks jeffmartins! It works

Not applicable

Re: For Loop to store all related files

Thanks Rob

Community Browser