By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

How to check only one dir in filesystemwatch

P: n/a
I try to monitor a directory for new created files that in this example
shall be moved to another dir. So far it looks like working as it should but
after the first file (one file copied into the dir) it detect a new file
created and go trough the routine again.
I have turned off the IncludeSubdirectories but it still do it

The code is the following

Imports System.IO

Public Class frmFileWatcher

Inherits System.Windows.Forms.Form

Private WithEvents fsWatchObj As FileSystemWatcher

Dim DispMessage As Boolean

Private Sub SetupWatcher(ByVal PathToWatch As String)

fsWatchObj = New FileSystemWatcher(PathToWatch)

fsWatchObj.IncludeSubdirectories = False ' True

fsWatchObj.EnableRaisingEvents = True

fsWatchObj.NotifyFilter = fsWatchObj.NotifyFilter Or _


fsWatchObj.NotifyFilter = fsWatchObj.NotifyFilter Or _


AddHandler fsWatchObj.Created, New FileSystemEventHandler(AddressOf

End Sub

Private Sub FileCreated(ByVal s As System.Object, ByVal EventInfo As

Dim DisplayMessage As String

If (EventInfo.ChangeType = WatcherChangeTypes.Created) Then

DisplayMessage = "File " & EventInfo.Name & " was "

DisplayMessage &= EventInfo.ChangeType.ToString & " at " &



FileCopy(EventInfo.FullPath, "e:\resizer\ut\" & EventInfo.Name)

End If

End Sub

Private Sub FileRenamed(ByVal s As System.Object, ByVal EventInfo As

Dim DisplayMessage As String

DisplayMessage = "File " & EventInfo.OldName

DisplayMessage &= " was renamed " & EventInfo.Name & " at " &


End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click

If txtDirToWatch.Text = "" Then

MessageBox.Show("Please enter path to watch", "Enter Path",
MessageBoxButtons.OK, MessageBoxIcon.Warning)


Call SetupWatcher(txtDirToWatch.Text)

End If

End Sub

End Class

Petter L.
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.