Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
saniyask
Creator
Creator

Fetching Data from Sub directory

Dear All,

I have a requirement where I need to fetch multiple csv's from a path which is eg:- C:Data\Qlik\PlantName\InnerFolder\Week\'.csv'

I need to create a loop which will start from C:Data\Qlik

2. It will open the subfolder 

3. Once its inside the subfolder it will search for an innerfolder and search for a folder name WEEK and load all the files from that folder.

4. If Week is not present in the innerfolder the loop will search for the file in the next subfolder and so on. (bcz there are multiple Plantname folders in the Main Qlik folder).

I have tried using for each but it doesn't work on three levels, can anyone suggest a solution please.

Labels (2)
1 Solution

Accepted Solutions
rubenmarin

Hi, it may be something like:

for each PlantDir in dirlist ('C:\Data\Qlik\*')
  for Each InnerFolder in dirlist (PlantDir)
    for each WeekFolder in dirlist (InnerFolder)
      IF Upper(Subfield('$(WeekFolder)','\',-1))='WEEK' THEN
        LOAD
          *
        From [$(WeekFolder)\*.csv]
          (txt, utf8, embedded labels, delimiter is ',', msq)
        ;
      ENDIF
    next
  next
next

 

View solution in original post

2 Replies
rubenmarin

Hi, it may be something like:

for each PlantDir in dirlist ('C:\Data\Qlik\*')
  for Each InnerFolder in dirlist (PlantDir)
    for each WeekFolder in dirlist (InnerFolder)
      IF Upper(Subfield('$(WeekFolder)','\',-1))='WEEK' THEN
        LOAD
          *
        From [$(WeekFolder)\*.csv]
          (txt, utf8, embedded labels, delimiter is ',', msq)
        ;
      ENDIF
    next
  next
next

 

saniyask
Creator
Creator
Author

Thanks for the response