Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

loop through to load all files from a folder and its subfolders?

Hi all,

This is my folder structure

MainFolder

       SubFolderr1

                      File1

                      File2

       SubFolder2

                      File3

                      File4

       SubFolder3

                      File5

                      File6

How to load all the files dynamically if i give only "MainFolder" Name.

Thanks in advance

Regards

Kumar

29 Replies
hic
Former Employee
Former Employee

Yes, no problem. I use

Sub ScanFolder(Root)

   for each FileExtension in 'csv'

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

         ...

End Sub

But you should instead use

Sub ScanFolder(FileExtension, Root)

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

      ...

End Sub

HIC

uacg0009
Partner - Specialist
Partner - Specialist

Hi Henric,

Is it possible to load files stored not in a folder in my computer, but from Internet?

I tried Call Scanfolder('http:\\00.00.0.00\data\qlikview') and end up with no result. But I can successfully load a single file from the same address.

BR, Aiolos

hic
Former Employee
Former Employee

To my knowledge, it is not possible to use the http protocol for this, since there is no possibility to browse a folder using http. In principle, it should be possible to use ftp though.

HIC

ngrunoz
Contributor II
Contributor II

Hi Henric. I am new to qlikview and am not so conversant with programming. Please may you help me follow through this synthesis.

When I copied the script its showing me some errors.

hic
Former Employee
Former Employee

This script is OK. You are right that the color coding and the squiggly lines make it look as if there is a problem, but there isn't. What happens is that the parser gets lost at $(Concatenate) which it cannot interpret (since it gets it value only when the script is run.

Change the path in the Call statement to something that exists on your computer, and I'll bet you it works.

HIC

Anonymous
Not applicable
Author

Hi Henric,

I am getting below error, could you please help me

error.PNG

My script as follows

script.PNG

hic
Former Employee
Former Employee

The ( ... file specification ...) is just a placeholder for the real file specification. You need to replace this with a file specification that fits your file. Use the file wizard (the button "Table Files") to create one that is OK.

HIC

Anonymous
Not applicable
Author

The loop works great for some of my datasets, however, I am having an issue with a few of them.

For some of the datasets, field names are changed when running the data sets through the loop. For example, rather then feeding in [Region] we feed in [Region]; similarly, rather then feeding in [PrimaryID] we feed in [PrimaryID].

Does anyone happen to know why this may be happening, or how I can correct this? Appreciate any help.

Tyler_Waterfall
Employee
Employee

Are you loading from Excel files or text files?

If so, check the headers for those files to make sure there are no special characters or weirdness there. I've seen issues like this because of "invisible" character in the source files.

If you are not sure which files are causing the issue, you could add in your load * statement another two fields:

filename() as file_name,

recno() as file_record_number

And then select the data that looks bad and see what file_name is associated with it. (I guess the record_number is not useful in this case, but maybe later ).

ngrunoz
Contributor II
Contributor II

Hi Heric,

Is  it possible to add an IF Condition of an other condition to say if Set Variable is =X then  execute the Sub Else skip the Sub.