Search code examples
csvluaeventtriggerfile-monitoring

File-Monitoring via Lua Script


Good evening,

I am currently developing a way to import machine created data from a csv sheet into a database. The question I have is, is there a way to react to a change in a csv file with Lua.

The file gets a line in this format:

17162H,"801234500001",9/23/2016 12:33:30 PM,"INV"

Every time a scanner is finishing a scan process, added under the old lines, but there is no direct connection to the database, to trigger the script.

It doesn't matter if the change is detected via different file size, foldersize (of the folder that contains the file) or a change within the file information (like date of last opening), but I can't open and read in it permanently due performance reasons.

Also this is the first time I ask here, so sorry for my clunky way, I'll try to improve myself with that over time.


Solution

  • If you need to run this on Windows, you can use winapi library, which supports file watchers. Here is an example of how it's used in one of my projects; you'll need to call winapi.sleep() to allow time for the check to trigger.