Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
agordon66
New Contributor

Get a list of files

Hello! So I want  to get all the files from a directory in Qlik Sense Desktop.

Found a nice post on the forum

Set vConcatenate = ;

FileList:

LOAD

'' AS SourceFile

AUTOGENERATE 0;

sub ScanFolder(Root)

          for each FileExtension in 'qvw'

                    for each FoundFile in filelist(Root & '\*.' & FileExtension)

                              FileList:

                              LOAD '$(FoundFile)' as SourceFile

       AUTOGENERATE 1;

                            

                              Set vConcatenate = Concatenate;

                    next FoundFile

          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('C:\Users\Public\Pictures\Sample Pictures\') ;


But It's not working. The FoundFile variable is always null. I've tried with different methods and I get Null every time.

There is another example on this page Attribute ‒ Qlik Sense

But those are not working either.

What is wrong?

Tags (2)
1 Solution

Accepted Solutions
rittermd
Honored Contributor

Re: Get a list of files

I just ran this code against one of my Data Connections and added a .csv extenstion and it ran and returned all of the files correctly.

I would suggest that you try this code.  Create a data connection to your folder and then change the lib statement to point to the name of the new data connection.

That should work

12 Replies
rittermd
Honored Contributor

Re: Get a list of files

If you are in Qlik Sense I think the issue is that you are looking for qvw extensions which are QlikView.  You want to look for qvf extensions for Qlik Sense.

agordon66
New Contributor

Re: Get a list of files

The Extension is not the problem. I wanted to look for pictures originally then I changed the extension. The extension variable is working. The problem is probably with the file path and how it concatenates the Root, wildcard and extension.

rittermd
Honored Contributor

Re: Get a list of files

Try putting some trace statements in your script and maybe you can see where it is going wrong.

agordon66
New Contributor

Re: Get a list of files

This is getting annoying.

Found another example in the documentation http://help.qlik.com/en-US/sense/3.1/Subsystems/Hub/Content/Scripting/ScriptControlStatements/For%20...

Still Not working.

agordon66
New Contributor

Re: Get a list of files

I might be crazy but I think that the wildcard is not evaluated

Re: Get a list of files

Hi,

try using this approach...

How to use regular expressions

It's a QlikView file, but you could try the same approach in Sense.

Br,

Andrea

rittermd
Honored Contributor

Re: Get a list of files

I just ran this code against one of my Data Connections and added a .csv extenstion and it ran and returned all of the files correctly.

I would suggest that you try this code.  Create a data connection to your folder and then change the lib statement to point to the name of the new data connection.

That should work

agordon66
New Contributor

Re: Get a list of files

I think that something is missing from that example because it just "loads" from some files and 2 inline tables, but the files are not set in the download section.

agordon66
New Contributor

Re: Get a list of files

Yes! It finally Worked with a connection.

Created Images Folder Connection then modified the script and all images were loaded. Thanks!

Set vConcatenate = ;

FileList:

LOAD

'' AS SourceFile

AUTOGENERATE 0;

sub ScanFolder(Root)

          for each FileExtension in 'jpg'

          let vThing = Root & '*.' & FileExtension;

                    for each File in filelist(vThing)

                              FileList:

                              LOAD '$(File)' as SourceFile

       AUTOGENERATE 1;

                            

                              Set vConcatenate = Concatenate;

                    next File

          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('lib://Images/') ;

Community Browser