Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
cbushey1
Creator III
Creator III

Check if exists - Script file

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?



1 Solution

Accepted Solutions
cbushey1
Creator III
Creator III
Author

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;

View solution in original post

2 Replies
m_woolf
Master II
Master II

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

cbushey1
Creator III
Creator III
Author

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;