Loop Through Files in a Folder

Qlik Sense supports a really simple process for importing a series of files that have the same structure (think a collection of daily comma separated files). You can simply use a wildcard when load the file and that is great but if you need to go back and link the data to the source file you need a different approach.

The following sample demonstrates how to loop through a location and load in a collection of files and include the file name along the way, which is great for traceability.

/*

Sample script to loop through files in a folder and then import into Qlik

Script will work in both QlikView and Qlik Sense though need to update file location synatx to drive path syntax for Qlik View

*/

 
For Each file in FileList ( 'lib://Qlik_Data/*.txt' )		// 'file' is variable name

[My Data]:
Load

	// Custom fields
	'$(file)'														As [Source file]	// Including filename as field gives ability to traceback to source data

	// Standard fields
	a,
	b,
	c

From [$(file)]
(fix, codepage is 28591, no labels, header is 1 lines);
Next file;
Next
Next

Tiered Security with Section Access