This way they can be manipulated from clients if necessary by using: ('endWatchA', 1) I implemented multiple watchers, modified polling to use WatchService.take for immediate notification of changes, and created Gateway Tag Change scripts to govern each watcher’s start and stop. I just wanted to update with the final code I used as my solution, in case it can help anyone. ("New File",p.resolve(e.context()).toString()) P = File("C:\\Users\\kylec\\Downloads").toPath() if currentValue.value:įrom import FileSystems,Files Place this script on a boolean tag, and change the folder path in line 16. It writes the results to a tag called New File. What scope are you running the script from? I just tried in the designer and the gateway, from a tag event, and it worked fine.įor reference, here is the script I ran from a valueChanged event on a tag. That is weird that it isn’t working for you. After this code runs once in the Gateway, can Client scripts instantiate new FileWatcher variables, and pass directory paths to the constructor? Kind of a catch-all question: I need to allow users to register selected directories to the WatchService. If this script resides on the Gateway, is the Global scope shown here accessible from Clients? I had read that Memory Tags were the preferred method for scoping variables globally. If I put this code in a Gateway Startup Event Script, should I set the script to run on a dedicated thread? If so should I still call the Watcher loop asynchronously? In general, would this be a proper place to put this kind of script? The listener function is called asynchronously so that it can safely run a continuous loop without preventing other processes. Upon construction, the init function is called automatically, which in turn initiates the Watcher’s listener loop. My questions are:įor my understanding, this code instantiates a new variable of type FileWatcher in the Global scope. csv to SQL but I want the Watcher to listen for new files and trigger that process. I have written project scripts that will parse and transfer the. csv files that are automatically generated by equipment. Like the OP, I want to utilize the WatchService to monitor a directory for new. I am new to most of this and so the minor aspects of implementation tend to go over my head. Use ().kill() to turn it off, and ().run() to turn it back on. This will create a single watcher, and store a reference to it in globals. Print Files.probeContentType(p.resolve(e.context())) Key = p.register(watcher,swek.ENTRY_CREATE,swek.ENTRY_DELETE,swek.ENTRY_MODIFY) Watcher = FileSystems.getDefault().newWatchService() Here is some code that uses WatchService from import FileSystems,Filesįrom import StandardWatchEventKinds as swekįrom import TimeUnit
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |