Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

retko1985
Contributor II

How to Load File Names in a Folder to a Table?

Hello,

I tried something like this:

FOR Each vFile in FileList('$(vFileDir)*.csv')

A:

        LOAD

            filename() AS AAA        

        FROM

            [$(vFile)]

            (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT vFile;

Unfortunate it doesn't work. What I want is to have 1 row for every file name in the folder. But I get as many rows as the file have and every row has file name. This seems to be also quite slow. Tried to use FirstValue, but it is also slow.

Do you have some advices please?

Thanks

1 Solution

Accepted Solutions
Highlighted

Re: How to Load File Names in a Folder to a Table?

Way simpler. vFile already contains the file name, so why do you want to open each file again?

FOR Each vFile in FileList('$(vFileDir)*.csv')

  A:

  LOAD '$(vFile)' AS FileName

  AUTOGENERATE 1;   

NEXT vFile;

You can add RowNo() AS ID to get a sequential number for each filename.

View solution in original post

5 Replies
enriquem
Contributor

Re: How to Load File Names in a Folder to a Table?

Hi!

Try this:

FOR Each vFile in FileList('$(vFileDir)*.csv')

A:

        LOAD

            filename() AS AAA       

        FROM

            [$(vFile)]

            (txt, utf8, embedded labels, delimiter is ',', msq)

        ORDER BY

             AAA;

NEXT vFile;

Regards!

Kind Regards,
Enrique Mora.
big_dreams
Contributor III

Re: How to Load File Names in a Folder to a Table?

might be distinct keyword help you..

FOR Each vFile in FileList('$(vFileDir)*.csv')

A:

        LOAD

            filename() AS AAA       

        FROM

            [$(vFile)]

            (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT vFile;

or use FIRST keyword

FOR Each vFile in FileList('$(vFileDir)*.csv')

A:

        First

        LOAD

            filename() AS AAA       

        FROM

            [$(vFile)]

            (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT vFile;

Regards,

Highlighted

Re: How to Load File Names in a Folder to a Table?

Way simpler. vFile already contains the file name, so why do you want to open each file again?

FOR Each vFile in FileList('$(vFileDir)*.csv')

  A:

  LOAD '$(vFile)' AS FileName

  AUTOGENERATE 1;   

NEXT vFile;

You can add RowNo() AS ID to get a sequential number for each filename.

View solution in original post

YoussefBelloum
Esteemed Contributor

Re: How to Load File Names in a Folder to a Table?

Hi,

if you want ONLY the name without the extension, use FileBaseName() function

https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/Scripting/FileFunctions/...

retko1985
Contributor II

Re: How to Load File Names in a Folder to a Table?

Exactly what I wanted

Thank you.