From: Mike Beebe on 5 Mar 2010 13:13 I trying to be notified when a directory is created, deleted, renamed or moved. What am I doing wrong? moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "") moFolderSysWatch.IncludeSubdirectories = True moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName moFolderSysWatch.EnableRaisingEvents = True
From: Herfried K. Wagner [MVP] on 5 Mar 2010 20:42 Am 05.03.2010 19:13, schrieb Mike Beebe: > I trying to be notified when a directory is created, deleted, renamed or > moved. What am I doing wrong? > > moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "") > moFolderSysWatch.IncludeSubdirectories = True > moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName > moFolderSysWatch.EnableRaisingEvents = True So, are you sure you are setting up the event handlers, either by making 'moFolderSysWatch' and 'WithEvents' variable and using 'Handles' at the event handler procedures, or by adding the handler using the 'AddHandler' statement? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: Mike Beebe on 9 Mar 2010 09:11 Here's my code (snippets): Private WithEvents moFolderSysWatch As FileSystemWatcher Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "") moFolderSysWatch.IncludeSubdirectories = True moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName moFolderSysWatch.EnableRaisingEvents = True End Sub Private Sub moFolderSysWatch_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles moFolderSysWatch.Renamed Debug.Print("moFolderSysWatch_Renamed") RenamedFolder(e) End Sub Private Sub RenamedFolder(ByVal e As System.IO.RenamedEventArgs) 'Needed for cross-thread calls If Me.InvokeRequired Then 'are we running on a secondary thread Dim d As New RenamedFolderDelegate(AddressOf RenamedFileHandler) Me.Invoke(d, New Object() {e}) Else RenamedFolderHandler(e) End If End Sub 'Needed for cross-thread calls Private Delegate Sub RenamedFolderDelegate(ByVal e As System.IO.RenamedEventArgs) Private Sub RenamedFolderHandler(ByVal e As System.IO.RenamedEventArgs) lstFiles.Items.Add(Now.ToString() & " Renamed '" & e.OldFullPath & _ "' to '" & e.FullPath & "'") End Sub "Herfried K. Wagner [MVP]" wrote: > Am 05.03.2010 19:13, schrieb Mike Beebe: > > I trying to be notified when a directory is created, deleted, renamed or > > moved. What am I doing wrong? > > > > moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "") > > moFolderSysWatch.IncludeSubdirectories = True > > moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName > > moFolderSysWatch.EnableRaisingEvents = True > > So, are you sure you are setting up the event handlers, either by making > 'moFolderSysWatch' and 'WithEvents' variable and using 'Handles' at the > event handler procedures, or by adding the handler using the > 'AddHandler' statement? > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> > . >
From: Armin Zingler on 9 Mar 2010 09:38 Am 09.03.2010 15:11, schrieb Mike Beebe: > Dim d As New RenamedFolderDelegate(AddressOf RenamedFileHandler) I don't find "RenamedFileHandler". -- Armin
From: Mike Beebe on 9 Mar 2010 11:09
Sorry, that should have been RenamedFolderHandler. The corrected code is below. Imports System.IO Imports System.Threading Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " #End Region Private m_WatchDirectory As String Private WithEvents moFolderSysWatch As FileSystemWatcher Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load m_WatchDirectory = Application.StartupPath m_WatchDirectory = m_WatchDirectory.Substring(0, _ m_WatchDirectory.LastIndexOf("\")) m_WatchDirectory &= "\Files" moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "") moFolderSysWatch.IncludeSubdirectories = True moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName moFolderSysWatch.EnableRaisingEvents = True End Sub Private Sub moFolderSysWatch_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles moFolderSysWatch.Renamed Debug.Print("moFolderSysWatch_Renamed") RenamedFolder(e) End Sub Private Sub RenamedFolder(ByVal e As System.IO.RenamedEventArgs) 'Needed for cross-thread calls If Me.InvokeRequired Then 'are we running on a secondary thread Dim d As New RenamedFolderDelegate(AddressOf RenamedFolderHandler) Me.Invoke(d, New Object() {e}) Else RenamedFolderHandler(e) End If End Sub 'Needed for cross-thread calls Private Delegate Sub RenamedFolderDelegate(ByVal e As System.IO.RenamedEventArgs) Private Sub RenamedFolderHandler(ByVal e As System.IO.RenamedEventArgs) lstFiles.Items.Add(Now.ToString() & " Renamed '" & e.OldFullPath & _ "' to '" & e.FullPath & "'") End Sub End Class "Armin Zingler" wrote: > Am 09.03.2010 15:11, schrieb Mike Beebe: > > Dim d As New RenamedFolderDelegate(AddressOf RenamedFileHandler) > > > I don't find "RenamedFileHandler". > > > -- > Armin > . > |