Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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
An alternatively to a check if a file exists you could use a load per filelist: Dynamically Loading Multiple Excel Files.
- Marcus
Hi,
This still doesn't work, sorry
-Dick
it just sais:
script line error:
IF filetime($(var_datasourcespath1)$(var_datasourcefile))>0 then
and then it starts executing the rest of the script.
Your variables contain string-values and therefore you need to add single-quotes around them like:
filetime('$(var_datasourcespath1)''$(var_datasourcefile)')
- Marcus
This is working in my case:
if filetime('$(var_datasourcespath1)$(var_datasourcefile)') > 0 then
I would use a for..each loop combined with the filelist() function
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