Recursive QVD index script snippet for Qlik Sense & QlikView

February 16, 2020

This simple snippet works with Qlik Sense and QlikView 12+ to recursively collect metadata from QVD files.

QVD indexer

The simple table produced includes only basic QVD metadata

The snippet is available below, or the latest version is on GitHub.

// Sub to recursively load QVD file metadata from a directory
SUB sLoadQVDMetadata(vSub_Path)

	TRACE >> Loading files in path [$(vSub_Path)].;
    
	// Iterate over each QVD file in the directory and load metadata
	// Use backslash for compatibility with QlikView 12
	FOR EACH vSub_File in FileList('$(vSub_Path)\*.qvd')
        
        	// For use with QlikView 12, comment out the two lineage rows
        	Metadata_QVD:
        	LOAD
			QvBuildNo,
			CreatorDoc,
			CreateUtcTime,
			SourceFileSize,
			"TableName",
			RecordByteSize,
			NoOfRecords,
			Offset,
			"Length",
			"Lineage/LineageInfo/Discriminator",
			"Lineage/LineageInfo/Statement",
			%Key_QvdTableHeader_B94FCCAC68ED3E20,
			FileName()				AS [File Name],
			FileSize()				AS [File Size]
        	FROM [$(vSub_File)]
        	(XmlSimple, table is [QvdTableHeader]);
        
        	// Set a count and print to console
        	LET vLoad_Rows = NoOfRows('Metadata_QVD');
        	TRACE >>> Loaded $(vLoad_Rows) rows, last file found: [$(vSub_File)].;
        
    	NEXT vSub_File;

	// Now recursively call the function for each directory found in this path
    	// Use backslash for compatibility with QlikView 12
    	FOR EACH vSub_Directory in DirList('$(vSub_Path)\*')

		// Resursively call sub
        	CALL sLoadQVDMetadata('$(vSub_Directory)');

    	NEXT vSub_Directory;

END SUB;

// Qlik Sense - i.e. lib, do not include trailing slash
Call sLoadQVDMetadata('lib://Dir_QlikFiles');
// QlikView - i.e. path (do not include trailing slash)
// Call sLoadQVDMetadata('D:\QlikFiles');

Profile picture

From Dave, who writes to learn things. Thoughts and views are his own.

© 2024, withdave.