Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have been having an issue when looping through folders in Qlik, so far this is my script:
I do pretty much exactly that in the app I use for log analysis for Qlik Sense. Have a look in the load script of the app named "LogAnalysis_V8.qvf" that you can download from here:
The key section is the one named "File loading" where the following two functions are defined:
Sub GetFiles(dir)
for each Ext in 'log', 'txt'
for each vFile in FileList('$(dir)/*.$(Ext)')
FilesRaw:
Concatenate LOAD
'$(vFile)' AS FileName,
SubField(Left('$(vFile)', Len('$(vFile)') - Len('Z.$(Ext)')),'_',-1) as FileTimeRaw
AUTOGENERATE 1;
next vFile;
next Ext;
end sub;
sub GetFilesRecursive(dir)
trace GetFilesRecursive: $(dir);
call GetFiles('$(dir)');
for each vDir in DirList('$(dir)/*')
call GetFilesRecursive('$(vDir)');
next vDir;
End Sub;
The function "GetFilesRecursive" traverses the whole folder structure, while the function "GetFiles" loads all file names in a specific folder into a table called "FilesRaw".