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?

Dynamic[Plot[stuffs]]? – kale Dec 07 '12 at 20:13FileByteCount.FileHashcould be faster though... – kale Dec 08 '12 at 14:55FileByteSizeis much much faster. – kale Dec 08 '12 at 16:08lastModified = {};withlastModified =FileDate[fileName, "Modification"]– Conor Feb 12 '21 at 20:54