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

Conditional Load of Files in the directory

Hi everyone,

I have the following directory  C:\Root\Parent Folder\SubFolders. The two SubFolders  are as follows

CA and IR (subfolders). So I would to like to have a situation like this:

If vSubFolder = 'CA' then

Load file1,fil2,....

else 

if vSubFolder = 'IR' then 

Load file3,file4,...

Please assist

Thanks

 

 

1 Solution

Accepted Solutions
ahmed_hassan
Contributor III
Contributor III

// subroutine
sub ScanFolder(Root)
for each Ext in 'DocumentLog.txt' // use this to identify file names to load
//for each Ext in 'txt' // or simply indicate an extension types to load
for each FoundFile in filelist(Root & '\*' & Ext)
FileList: // don't worry about the squigly lines. they are there because of the concatenate variable. will run fine.
$(Concatenate)
load *
from [$(FoundFile)](txt, utf8, no labels, delimiter is '\t', msq, no eof); // parameters here might change depending on the files you are loading

set Concatenate = concatenate;
next FoundFile
next Ext

for each SubDirectory in dirlist(Root&'\*')
call ScanFolder(SubDirectory)
next SubDirectory
end Sub

// place the root directory you want to cycle through here.
Call ScanFolder('C:\QlikView Application Folders\DistributionService\1\Log');

For more info check: http://livingqlikview.com/looping-through-files/

View solution in original post

6 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

I am not sure what your question is. How is vSubFolder set?
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
zwyne
Creator
Creator
Author

I thought may be I should first declare a variable, but maybe let me not include the variable.

ahmed_hassan
Contributor III
Contributor III

Why do you need "if" or "else" ?

 

you can normally do it as following:

Load 

Field1, Field2

From  [C:\Root\Parent Folder\CA\ Filename.qvd]  ( note: you can use " %" or " *"   e.g  " *.xlsx"  it will load all xlsx files)

 

Noconcatenate 

Load

Field1, Field2

From  [C:\Root\Parent Folder\IR\ Filename.qvd]

zwyne
Creator
Creator
Author

Hi again, basically I want to load the two subfolders conditionally i.e
If Subfolder= CA then
load file1,file2
else
if Subfolder = IR
load file3,file4
end
ahmed_hassan
Contributor III
Contributor III

// subroutine
sub ScanFolder(Root)
for each Ext in 'DocumentLog.txt' // use this to identify file names to load
//for each Ext in 'txt' // or simply indicate an extension types to load
for each FoundFile in filelist(Root & '\*' & Ext)
FileList: // don't worry about the squigly lines. they are there because of the concatenate variable. will run fine.
$(Concatenate)
load *
from [$(FoundFile)](txt, utf8, no labels, delimiter is '\t', msq, no eof); // parameters here might change depending on the files you are loading

set Concatenate = concatenate;
next FoundFile
next Ext

for each SubDirectory in dirlist(Root&'\*')
call ScanFolder(SubDirectory)
next SubDirectory
end Sub

// place the root directory you want to cycle through here.
Call ScanFolder('C:\QlikView Application Folders\DistributionService\1\Log');

For more info check: http://livingqlikview.com/looping-through-files/
zwyne
Creator
Creator
Author

Thank you , it make sense