Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Fellow Qlikies, I am trying to check if a script file (.qvs) exists inside a folder and if it does load it, else load a different one.
Example:
If this exists in the file directory (SomeScript_BD.qvs) then use the must_Include to read it into the application, if it doesnt exist, use the Must_Include for this file (SomeScript.qvs).
As I write this I am thinking I might be able to create a table use DoDir approach that lists all the filenames as fields and then if use a function to check if the filename exists in this list.
Does anyone have any thoughts?
thanks for the reply mw.
I ended up doing something a bit more elaborate to incorporate the loop functionality with my Must_includes.
SET vRoot = '..\..\..\..\SQL Script Library\';
/* Builds a list of Only Custom scripts in the folder*/
FOR Each Ext in 'qvs'
//
FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)
ScriptList:
Load
SubField('$(File)','\',-1) as ScriptFullName
, SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1) as GenericScriptName
autogenerate 1
Where SubField('$(File)','\',-1) like '*_BD*';
next File
FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)
Concatenate (ScriptList)
Load
SubField('$(File)','\',-1) as ScriptFullName
, SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1) as GenericScriptName
autogenerate 1
Where NOT EXISTS(GenericScriptName,SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1));
next File
next Ext
/* Loop and load the the must_include statements for all the scripts that are required for this client */
For i = 1 to NoOfRows('ScriptList')
Let vFileName = Peek('ScriptFullName',$(i),'ScriptList');
$(Must_Include='..\..\..\..\SQL Script Library\$(vFileName)');
Next i
DROP TABLES ScriptList;
Let vFile = 'Your first qvs file path';
LET vFileExists = if(FileSize('$(vFile)') > 0, -1, 0);
IF $(vFileExists) THEN
//Must_include the first file here
ELSE // File does not exist
//Must_include the Second file here
ENDIF
thanks for the reply mw.
I ended up doing something a bit more elaborate to incorporate the loop functionality with my Must_includes.
SET vRoot = '..\..\..\..\SQL Script Library\';
/* Builds a list of Only Custom scripts in the folder*/
FOR Each Ext in 'qvs'
//
FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)
ScriptList:
Load
SubField('$(File)','\',-1) as ScriptFullName
, SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1) as GenericScriptName
autogenerate 1
Where SubField('$(File)','\',-1) like '*_BD*';
next File
FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)
Concatenate (ScriptList)
Load
SubField('$(File)','\',-1) as ScriptFullName
, SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1) as GenericScriptName
autogenerate 1
Where NOT EXISTS(GenericScriptName,SubField(SubField(SubField('$(File)','\',-1),'_',1),'.',1));
next File
next Ext
/* Loop and load the the must_include statements for all the scripts that are required for this client */
For i = 1 to NoOfRows('ScriptList')
Let vFileName = Peek('ScriptFullName',$(i),'ScriptList');
$(Must_Include='..\..\..\..\SQL Script Library\$(vFileName)');
Next i
DROP TABLES ScriptList;