Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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