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: 
Not applicable

Monitor a Folder for the Creation of File (csv), then Load

Hi all,

Is it possible to have a macro to pole a folder and when a csv file is added for it to be loaded into QV?

Any help on how to do this will be great!

1 Solution

Accepted Solutions
Not applicable
Author

I've managed to solve this problem..... pretty simple - I've added 2 as the bWaitOnReturn part of the WshShell.Run script (that executes my Python Script).

A text box will open once Python is finished (file would be there) & I now know when to reload the data.

Thanks for all the suggestions.

View solution in original post

11 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

You mean, an otherwise empty folder will suddenly contain one or more .csv files and QlikView should immediately load them. Or do you mean that QlikView should load a new file in a directory of existing .csv files as soon as it appears? Only then and never again afterwards?

Both can be handled by QlikView exclusively by creating a document that loads .csv files and by creating a server reload task that runs at regular intervals (say every 5 mins)

Peter

Not applicable
Author

HI Peter,

Yes to the 1st - empty folder & when a csv is place in there for QV to immediately load the data.  I'm looking to trigger this action via a button.

I have no idea how to code this & had no joy with Google.

many thanks

tamilarasu
Champion
Champion

You can try something like below,

If FileSize('C:\Users\Tamil\Desktop\Test\*.csv')>0 then
Data:

LOAD Data
FROM

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

ELSE 


Temp:
Load MsgBox ('No files found in the folder!','Status','OKCANCEL','ICONHAND') AutoGenerate 1;
DROP Table Temp;

ENDIF

Not applicable
Author

‌thanks Tamil..... but what I require is it to loop / keep checking if a file is there & when it is - to old the data.

I just want 1 click to do this, rather than keep hitting reload.  A file will eventually be place in the folder as I've kicked off a script to execute another program.... but this program takes a few mins to complete.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Do you have the possibility to trigger a task at the end of the execution of the other program? For example, you've kicked off a script to execute another program - that could mean that you start a CMD file that will wait until the "other program" completes. Add a call to QMSEDX to the end of that CMD file that triggers the reload of your csv-reading-QlikView document. Nobody will waste any time (or cpu cycles) anymore polling a folder for files that may or may not appear. Seems more efficient to me...

Peter

Not applicable
Author

Your segestion will be possible (as python should be able to do this)..... but, this sounds more complex than code to poll a folder?

Do you have any links or examples to how I can go about this?

many thanks

Peter_Cammaert
Partner - Champion III
Partner - Champion III

On the contrary. Triggering a task only when there is some work to do is always simpeler and way more efficient than creating a program that has to sit and wait until an event (like what you are proposing) occurs. Moreover, the latter solution will consume memory and cpu cycles while doing nothing but wait.

You don't need python to do this, if only windows machines are involved. Assuming that the script you kicked off to start another program can also start a batch file (.CMD) instead, you could enter a statement to start the program in that batch file, followed by a call to QMSEDX to trigger a QlikView server task and reload the csv reader.

I am wary about listing examples as I don't know a thing about your environment and every example that doesn't apply to your situation will only make things look more complex. Can you elaborate on the chain of command from whoever launches the script up until the QlikView document that will actually make use of the csv data? Thanks.

Peter

Not applicable
Author

Basically the process is this: (on Windows 7)

Qlikview:

Button A:

1. Opens Explorer -> user selects a file

2. File is moved to a different location

3. Python script is executed (to do some data manipulation & outputs a csv file)

Button B:

4. Reloads data -> which is the csv file created in step 3....... but the timing for it's completion can vary.

So I'm looking for a way to load the data as soon as the csv file is placed in a folder.

I do not want to close QlikView or manually keep checking if the file is there.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Is there any objection against making step 3 wait for the python script to complete (at that moment, the csv file is present in the target folder) and adding a step 4 that does a reload?

Peter