Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Exit Script

I have loaded CSV files into QVW file. Now i have a requirement such that, in load script i have to write the script which will check that whether the files exist in the specified path or not. If not then it will exit the script without any error and if yes then it will transfer the CSV files to some other

How it can be done ??

5 Replies
Not applicable
Author

Hi,

you could test file existence in your loading script as follows

 

if isnull(filetime('c:\qv\data\myfile.txt')) then

//do nothing

else

//file is actually there, load it

table_1:

LOAD col1,

     col2

FROM

C:\QV\data\myfile.txt

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

end if

Hope this helps

Hilaire

Not applicable
Author

hi,
try below code in edit script.
let vDataPath ='c:\Project\Data\Source\';
DIRECTORY $(vDataPath) ;

let vMoveDataPath ='c:\Project\Data\Destination\';
DIRECTORY $(vMoveDataPath) ;

Set NoOfFiles = 0;
For each file in filelist ('$(vDataPath)*.txt');
Let NoOfFiles = NoOfFiles + 1;
next
If(NoOfFiles=0) then
Set vNoOfFiles = 0;
ELSE
Set vNoOfFiles =1;
ENDIF

SWITCH $(vNoOfFiles)

CASE 1
vErrorType = ScriptError;
vErrorDetail = ScriptErrorList;
IF(ScriptErrorCount=0) then
execute cmd.exe /c move "$(vDataPath)*.csv" "$(vMoveDataPath)";
ENDIF

CASE 0
EXIT Script

ENDSWITCH
i hope this helps you.
Regards
Venkat
adhudson
Creator II
Creator II

Hi,

     You can use the following script to match your requirement.

     if FileSize('$(FileName)')>0 THEN

    

         Load Statements

     Else

    

           Exit Script;

     ENDIF

Regards

Andrew Hudson

Not applicable
Author

Hi Hilaire,

Its working but now if mthe file is there then it should move to a specified path. How that will be done ??

Not applicable
Author

to move the file to another directory, you can use the syntax shown in Venkat's post above

execute cmd.exe /c move c:\qv\data\myfile.txt c:\qv\data\old\myfile.txt

BTW, using his sample code or taking code samples from Rob Wunderlich's "qlikview cookbook" will make your code more robust if you don't know the file name beforehand

the "move c:\qv\data\myfile.txt c:\qv\data\old\myfile.txt" is actually a DOS command, you can use other dos commands as well (copy, del, ...)

Hilaire