Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
dickelsa
Creator
Creator

Check for file in script

Hi guys,

Currently I'm loading my file with an wildcard and variables, looking like this:

SET var_datasourcefile='BC*.xml';

trace $(var_datasourcespath1)$(var_datasourcefile);

LOAD *

FROM $(var_datasourcespath1)$(var_datasourcefile);

that is working out great, but now I want to check if the xml file exists in the map, and if it doesnt exist, it should skip the script.

I thought it could be done like this:

SET var_datasourcefile='BC*.xml';

IF filetime($(var_datasourcespath1)$(var_datasourcefile))>0 then

LOAD *

FROM $(var_datasourcespath1)$(var_datasourcefile);


ENDIF


However, this doesn't seem to work, can anyone help me with this?


Thanks a lot!


Best regards,


Dick


1 Solution

Accepted Solutions
dickelsa
Creator
Creator
Author

Hi,

Considering my script, it is not possible to just 'loop through it'

i found the solution to the problem. As it turns out, for FileTime() you need the complete directory of the file, and not the relative path (my variables did only have the relative).

However, since i want my files to work no matter which pc or location I use, without editing the script I built a DIY relative path using the system function DocumentPath()

now it looks like this:

SET var_datasourcespath= 'Data\Sources\';

let var_thispath= DocumentPath();

let var_documenttitle= 'FileName.qvw';

trace $(var_documenttitle);

let var_thispath= Replace('$(var_thispath)','$(var_documenttitle)','');

trace $(var_thispath);

let var_datasourcespath= '$(var_thispath)$(var_datasourcespath)';

trace $(var_datasourcespath);

SET var_datasourcefile='BC*.xml';

LET var_FileName =  '$(var_datasourcespath)$(var_datasourcefile)';

TRACE 'Filename= $(var_FileName)';

IF FileTIme('$(var_FileName)')>0 THEN

LOAD *

FROM '$(var_datasourcespath)$(var_datasourcefile)';


ENDIF

It works like a charm now, so that is great!

Thanks for the help!

-Dick

View solution in original post

8 Replies
Anil_Babu_Samineni

Try to use IF , ELSE Condition

SET var_datasourcefile='BC*.xml';

IF filetime($(var_datasourcespath1)$(var_datasourcefile))>0 then

LOAD *

FROM $(var_datasourcespath1)$(var_datasourcefile);

ELSE IF

TRACE <<<Not Found>>>>;

ENDIF

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
marcus_sommer

An alternatively to a check if a file exists you could use a load per filelist: Dynamically Loading Multiple Excel Files.

- Marcus

dickelsa
Creator
Creator
Author

Hi,

This still doesn't work, sorry

-Dick

dickelsa
Creator
Creator
Author

it just sais:

script line error:

IF filetime($(var_datasourcespath1)$(var_datasourcefile))>0 then


and then it starts executing the rest of the script.



marcus_sommer

Your variables contain string-values and therefore you need to add single-quotes around them like:

filetime('$(var_datasourcespath1)''$(var_datasourcefile)')

- Marcus

Not applicable

This is working in my case:

if filetime('$(var_datasourcespath1)$(var_datasourcefile)') > 0 then

Colin-Albert

I would use a for..each loop combined with the filelist() function

QlikView Maven: Loading All of the Files from a Folder

dickelsa
Creator
Creator
Author

Hi,

Considering my script, it is not possible to just 'loop through it'

i found the solution to the problem. As it turns out, for FileTime() you need the complete directory of the file, and not the relative path (my variables did only have the relative).

However, since i want my files to work no matter which pc or location I use, without editing the script I built a DIY relative path using the system function DocumentPath()

now it looks like this:

SET var_datasourcespath= 'Data\Sources\';

let var_thispath= DocumentPath();

let var_documenttitle= 'FileName.qvw';

trace $(var_documenttitle);

let var_thispath= Replace('$(var_thispath)','$(var_documenttitle)','');

trace $(var_thispath);

let var_datasourcespath= '$(var_thispath)$(var_datasourcespath)';

trace $(var_datasourcespath);

SET var_datasourcefile='BC*.xml';

LET var_FileName =  '$(var_datasourcespath)$(var_datasourcefile)';

TRACE 'Filename= $(var_FileName)';

IF FileTIme('$(var_FileName)')>0 THEN

LOAD *

FROM '$(var_datasourcespath)$(var_datasourcefile)';


ENDIF

It works like a charm now, so that is great!

Thanks for the help!

-Dick