
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looping through Subfolders and Files
I was hoping to make a table of all files in the subfolders of a directory, but only if they are in a certain named folder.
As an example I need all excel files that are in a subfolder with a name of 'Templates'. I can't quite grasp my head around the loops in the typically file list script to know if I could just write some sort of expression string as the extension (See below).
sub DoDir (Root)
for each Ext in '\Templates\*.xlsx'
for each File in filelist (Root&'\*' &Ext)
LOAD
'$(File)' as Name,
FileSize( '$(File)' ) as Size,
FileTime( '$(File)' ) as FileTime
autogenerate 1;
next File
next Ext
for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir
end sub
In theory I could make a list of all files, but that will be quite a long list and was hoping I could tell it only to look in subfolders called 'Templates'
- Tags:
- qlikview_scripting
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Attached is a proposal: the objective is
make a table of all files in the subfolders of a directory, but only if they are in a certain named folder (Example : "Templates")
sub DoDir (Root)
for each File in filelist (Root&'\*' &Ext)
let vmatch = wildmatch('$(File)','*Templates*');
if '$(vmatch)'>0 then
LOAD
'$(File)' as Name,
FileSize( '$(File)' ) as Size,
FileTime( '$(File)' ) as FileTime
autogenerate 1;
end if
next File
for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir
end sub
Call DoDir('.\test\') ;
Taoufiq ZARRA
"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "
(you can mark up to 3 "solutions") 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Attached is a proposal: the objective is
make a table of all files in the subfolders of a directory, but only if they are in a certain named folder (Example : "Templates")
sub DoDir (Root)
for each File in filelist (Root&'\*' &Ext)
let vmatch = wildmatch('$(File)','*Templates*');
if '$(vmatch)'>0 then
LOAD
'$(File)' as Name,
FileSize( '$(File)' ) as Size,
FileTime( '$(File)' ) as FileTime
autogenerate 1;
end if
next File
for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir
end sub
Call DoDir('.\test\') ;
Taoufiq ZARRA
"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "
(you can mark up to 3 "solutions") 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the suggestion. I definitely think that will work and actually gives me other ideas. I was hoping the wildcard search could be used in a way to speed up the search though. I'll try to give it a test to make sure since I want the Templates to be in the folder directory, but that shouldn't matter based on your solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok
waiting for your feedback !
Taoufiq ZARRA
"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "
(you can mark up to 3 "solutions") 😉
.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have a look at the following Design Blog post as there is a pretty related example there:
https://community.qlik.com/t5/Qlik-Design-Blog/Loops-in-the-Script/ba-p/1473543
If you wish to further search this area, use the following base URL:
https://community.qlik.com/t5/Qlik-Design-Blog/bg-p/qlik-design-blog
Be sure to return once you get something working and either use the Accept as Solution button on an existing post or if you did something different, write that up and then use the button on it after you post it, this way the other Community Members know what actually worked and if you do one of the other posts, that gives credit to them...
Regards,
Brett
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
