When i try to set the watcher path to a single file like so:
watcher.Path = filePath1;
I get the error:
The directory name C:\Cromos 3.0\repository\diagnostics\dwm01_2011_06_13__09_03.LXD is invalid.
Can you only set the path to a folder directory?
Nope, filesystemwatchers run on their own thread.
Use FileSystemWatcher to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer.
If we want to notify the administrator, that a file has been changed, we would require the name of the file to which the change has been made. To get the name of the file we use the event handler argument FileSystemEventArgs.
Your error is setting the Path property with a full filename
watcher.Path = Path.GetDirectoryName(filePath1);
watcher.Filter = Path.GetFileName(filePath1);
should work.
Not related to your proper question, but, of course, to enable the FileSystemWatcher's functionality, it is imperative to set the EnableRaisingEvents property to true.
Yes, but you can watch for specific files by setting the filter property to the filename.
e.g.
watcher.Filter = "dwm01_2011_06_13__09_03.LXD";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With