I have a function the takes some time to complete. The function imports data from a .csv, parses it, and plots certain vectors from there. The .csv is constantly being updated from an external program. Ideally, the file size of the .csv would be monitored and when it changes the function is run. Here's what I have so far (assuming the described function is f
).
file = "testfile.csv"
Dynamic[
Refresh[
filesize:=FileByteCount[file];
data = Import[file, "CSV"];
f[data],TrackedSymbols:>{filesize},UpdateInterval->5]]
This works, but seems to run f
every 5 seconds no matter if the file size has changed or not. This doesn't seem to be very efficient. Also, if I try to use inside DynamicModule
it doesn't work at all.
So, what's the best way to monitor and execute code on a file change?