The Created event will be fired when a file is created for example. And don't reset the fileWatcher.Path = path; everytime. Because you overwrite the current path.
Foreach root you must create an dedicated FileSystemWatcher object!
// Wire events. watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.Created += new FileSystemEventHandler(watcher_Created); watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
How to monitor files in different folders using the FileSystemWatcher?
77elcomama
The Created event will be fired when a file is created for example.
And don't reset the fileWatcher.Path = path; everytime. Because you overwrite the current path.
Foreach root you must create an dedicated FileSystemWatcher object!
RajeshJV
Vargaj
And you resert the Filepath every time in the loop. For each root directory you need a dedicated FileSystemWatcher object.
B0tt
private ArrayList _watchers = new ArrayList();
protected void WatchRootDirectory( string root )
{
// Create filesystemwatcher and set property values.
FileSystemWatcher watcher = new FileSystemWatcher( root );
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Wire events.
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
// Add to collection.
_watchers.Add( watcher );
}
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " changed." );
}
private void watcher_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " created." );
}
private void watcher_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " deleted." );
}
BeyondTheSunset
Does anyone happen to have the VB 2005 version of this
I tried to figure it out but I've got the sqiggleez happening everywhere.
CplusplusBeginner
P.J. I couldn't thank you more
Chadh
Try:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx
I like it!
Welles