Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2022, LIVE in Denver CO., May 16-19, 2022. REGISTER NOW TO RECEIVE EARLY BIRD PRICING
cancel
Showing results for 
Search instead for 
Did you mean: 
retko1985
Creator II
Creator 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
Peter_Cammaert
Partner
Partner

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
Creator
Creator

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
Creator III
Creator III

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,

Peter_Cammaert
Partner
Partner

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
Champion
Champion

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
Creator II
Creator II
Author

Exactly what I wanted

Thank you.