Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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?

1 Solution

Accepted Solutions
rittermd
Master
Master

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

View solution in original post

12 Replies
rittermd
Master
Master

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.

Anonymous
Not applicable
Author

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

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

Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

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

Andrea_Ghirardello

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

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

Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

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/') ;