D
David
I have been working on trying to write a directory watcher service.
One of the requirments is that it be able to watch multiple
directories, not sub directories of one parent directory, but just
multiple directories.
I have hit a snag and don't know how to get around it.
Basically I read in a list of directories from the app.config and stuff
them into an array, so that I have something like this:
sDirsToWatch[0] = "C:\Temp"
sDirsToWatch[1] = "D:\Temp"
Then I do the following
For (i = 0; i < sDirsToWatch.Length; i++)
{
FileSystemWatcher myWatcher = new System.IO.FileSystemWatcher();
myWatcher.NotifyFilter = NotifyFilters.DirectoryName |
NotifyFilters.FileName | NotifyFilters.Attributes;
myWatcher.Deleted += new FileSystemEventHandler(LogDeleted);
myWatcher.Path = sDirsToWatch;
myWatcher.EnableRaisingEvents = true;
}
Now when it gets to either the .Path line or to when it gets to the
..EnableRaisingEvents for the 2nd directory, I get an error: Error
reading the D:\Temp directory
I think what is happening is that all of the objects that I am creating
are named the same, so its causing problems.
So my question is, how do I dynamically name my FileSystemWatcher
object ?
Any help would be most appreciated.
Thanks
David
One of the requirments is that it be able to watch multiple
directories, not sub directories of one parent directory, but just
multiple directories.
I have hit a snag and don't know how to get around it.
Basically I read in a list of directories from the app.config and stuff
them into an array, so that I have something like this:
sDirsToWatch[0] = "C:\Temp"
sDirsToWatch[1] = "D:\Temp"
Then I do the following
For (i = 0; i < sDirsToWatch.Length; i++)
{
FileSystemWatcher myWatcher = new System.IO.FileSystemWatcher();
myWatcher.NotifyFilter = NotifyFilters.DirectoryName |
NotifyFilters.FileName | NotifyFilters.Attributes;
myWatcher.Deleted += new FileSystemEventHandler(LogDeleted);
myWatcher.Path = sDirsToWatch;
myWatcher.EnableRaisingEvents = true;
}
Now when it gets to either the .Path line or to when it gets to the
..EnableRaisingEvents for the 2nd directory, I get an error: Error
reading the D:\Temp directory
I think what is happening is that all of the objects that I am creating
are named the same, so its causing problems.
So my question is, how do I dynamically name my FileSystemWatcher
object ?
Any help would be most appreciated.
Thanks
David