← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #698795]: Find Any Addition / removal of file in directory in parallel

 

Question #698795 on SikuliX changed:
https://answers.launchpad.net/sikuli/+question/698795

RaiMan proposed the following answer:
based on the baeldung example:

import java.nio.file.FileSystems as FileSystems
import java.nio.file.Paths as Paths
import java.nio.file.StandardWatchEventKinds as WatchKinds

watchService = FileSystems.getDefault().newWatchService();
path = Paths.get("<some existing folder>")
path.register(watchService, WatchKinds.ENTRY_CREATE)

print "Starting watch"
while True:
    key = watchService.take()
    if not key:
        print "... stopping"
        break
    print "... checking"
    for event in key.pollEvents():
        print event.context()
    key.reset();
    exit()

when started, it waits for a new file to show up in the given folder,
prints and exits.

Since watchService.take is blocking, it must run in a subprocess.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for SikuliX.