View Single Post
  #1 (permalink)  
Old December 27th, 2003, 10:31 PM
hugh@kmcnetwork.com hugh@kmcnetwork.com is offline
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default File System Watcher

Hello Everyone and thanks for your help in advance. I am developing an application that utilizes the FileSystemWatcher. However, I am having difficulty getting the application to determine the difference between a created file and a changed file. Here is my code:

        Dim myWatcher As New System.IO.FileSystemWatcher

        Dim myPath As String = "C:\My Documents"

        myWatcher.Path = myPath

        myWatcher.EnableRaisingEvents = True

        AddHandler myWatcher.Created, AddressOf logchange

        AddHandler myWatcher.Changed, AddressOf logchange

    Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)

        If e.ChangeType = WatcherChangeTypes.Created Then
            Label1.Text = e.FullPath & " was created"
        ElseIf e.ChangeType = WatcherChangeTypes.Changed Then
            Label1.Text = e.FullPath & " was changed"
        End If

    End Sub

When I test this, all new files created come up as "changed" rather than created. What ami I doing wrong? Any help would be greatly appreciated. Thanks.

Reply With Quote