Caution: when you do this kind of directory watching, what you are checking is almost always that the target file is being created. That is quite different from the file being ready for use. It is not possible for the operating system to detect that a file is "ready for use" by another process; on most operating systems it is messy even just to detect whether some process has a particular file open.
Because of these difficulties, it is not a good idea to rely just upon a file's existence to determine whether that same file is ready for use. You need to develop protocols to signal that the file is ready.
There are methods such as using "lock files" or semaphores or shared memory segments or memmap() to communicate information about whether a file is ready for use or not.
One of the useful methods is to create the file using a different name than the second system is looking for, and do all the I/O to the file using that name, close the file, and then have the writing process rename the file to become the name that the second system is checking for. If you do this, then the fact that the expected file name has come into existence signals that the file is ready for use, because the writing system did not allow the file to be that name until the file was ready.