Posted: 27 Nov 2018 14:04 EST Last activity: 5 Jul 2019 5:40 EDT
FileWatcher: "The path is not of a legal form."
I'm having difficultly implementing a FileWatcher in a robotic automation. I'm copying a pattern that is working in existing automations.
When the FileWatcher component is executed, this pop-up appears:
The message "the path is not of a legal form" is a .NET error message. The suggested fix for .NET is to ensure that the Path property is set on the FileWatcher object before setting the EnableRaisingEvents property to True. Indeed, if I set EnableRaisingEvents to False, the error does not occur (but it also does not continue in the automation because the Created event is not raised). However, I am unable to change the order of property assignment within the automation because I don't have access to the underlying code.
Below I have attached two automation snippets and two FileWatcher property pages. One automation and property page are the one I'm working on (new), and the other (old) are from a similar automation that does not have the problem. I cannot see why one works and the other does not.
I've tried re-creating the FileWatcher component, changing properties, etc. Nothing has resolved this issue.
I haven't figured out how to fix this, but I did design a workaround. The workaround is not as flexible as the complete FileSystemWatcher, but it works in my specific situation. I wrote a C# script.
The script is pasted below. Note the script requires using OpenSpan.Diagnostics; at the top of the file. This script waits for a file matching the pattern to appear in the path. This script will not work if a file matching the pattern already exists in the path (well, it will work, but it won't be locating a newly created file). Since I can ensure that directory is empty, this works for me.
I wasted enough time fooling with FileSystemWatcher and this is working now. I would still like to know what was wrong with my usage of the component, but I can't wait on it.
public bool WaitForFileCreated(string path, string filter, int timeoutSeconds)