Thanks for getting back with me. Much appreciated.
Anyway. I must of read an article similar to Jayesh Jain on another interent site before because I had been also playing with simialar example.
Anyway, Jain code works the sameway with the "Change Events" you are correct about limiting the number of "Notifyfilters" to use. I disagree on how Jain uses the following example set for the filter.
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.FileName
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.Attributes
These statements cause the "FileSystemWatcher" to change more then once for a single change on the file.
Instead use this ....
wf.NotifyFilter = IO.NotifyFilters.FileName
wf.NotifyFilter = IO.NotifyFilters.Attributes
Also, the programmer needs to decide what kind of event to watch for ie. "Change" or "Created". I would not use both for the same "FileSystemWatcher" class.
I used the "wf.NotifyFilter = IO.NotifyFilters.LastAccess" instead of Jain's example because it still detect the events without the "change" events occuring mupliple times.
Keep intouch and I will continue to look for your comments.
Below is what I had came up with...
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
wf = New System.IO.FileSystemWatcher
On Error Resume Next
wf.Path = Me.txtWatchPath.Text
wf.Filter = Me.txtBoxFilter.Text
wf.NotifyFilter = IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName
' add the handler to each event
AddHandler wf.Changed, AddressOf logChange
' add the rename handler as the signature is different
AddHandler wf.Renamed, AddressOf logRename
AddHandler wf.Error, AddressOf errorlogChange
On Error Resume Next
If Me.chkWatchsubDirecties.Checked = True Then
wf.IncludeSubdirectories = True
wf.IncludeSubdirectories = False
wf.EnableRaisingEvents = True
Me.btnStart.Enabled = False
Me.btnStop.Enabled = True
Me.txtBoxFilter.ReadOnly = True
' Turn off the update of the display on the click of the control.
Me.chkWatchsubDirecties.AutoCheck = False
Private Sub errorlogChange(ByVal source As Object, ByVal e As ErrorEventArgs)
Dim sMessages As String
' Show that an error has been detected.
If TypeOf e.GetException Is InternalBufferOverflowException Then
Me.txtFolderActivity.Text &= ( _
"The file system watcher experienced an internal buffer overflow: " _
Private Sub logChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
' Specify what is done when a file is changed, created, or deleted.
Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been changed" & _
" @" & TimeString & ControlChars.NewLine
'If e.ChangeType = WatcherChangeTypes.Created Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been created" & ControlChars.NewLine
'If e.ChangeType = WatcherChangeTypes.Deleted Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been deleted" & ControlChars.NewLine
Private Sub logRename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
Me.txtFolderActivity.Text &= ("File: " & e.OldName & " has been renamed to: " & e.Name & " " & ControlChars.NewLine)