• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

FSW

Why my  Me.txtDisplayFiles.Text does not display the path, name and time when a new file is added. It says only "modifiled"



Private Sub btnStartWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartWatch.Click


        WatchFolder = New System.IO.FileSystemWatcher

        If Me.txtWatchPath.Text = Nothing Then


            MessageBox.Show("Please check file path ", "Path   " & Now, MessageBoxButtons.OK, _
            MessageBoxIcon.Information)



        Else

            WatchFolder.Path = Trim(Me.txtWatchPath.Text)

            WatchFolder.NotifyFilter = IO.NotifyFilters.DirectoryName
            WatchFolder.NotifyFilter = NotifyFilters.FileName
            WatchFolder.NotifyFilter = NotifyFilters.Attributes

            AddHandler WatchFolder.Changed, AddressOf logchange
            AddHandler WatchFolder.Created, AddressOf logchange
            AddHandler WatchFolder.Deleted, AddressOf logchange

            AddHandler WatchFolder.Renamed, AddressOf logrename

            WatchFolder.EnableRaisingEvents = True
            btnStartWatch.Enabled = False
            btnStopWatch.Enabled = True



        End If

       

    End Sub




    Private Sub logchange(ByVal source As Object, ByVal e As _
                    System.IO.FileSystemEventArgs)
        If e.ChangeType = IO.WatcherChangeTypes.Changed Then
            Me.txtDisplayFiles.Text &= e.Name & _
                                    " - modified" & Now & vbCrLf

        ElseIf e.ChangeType = IO.WatcherChangeTypes.Created Then
            Me.txtDisplayFiles.Text &= e.FullPath & _
                                     " - created" & vbCrLf

        ElseIf e.ChangeType = IO.WatcherChangeTypes.Deleted Then
            Me.txtDisplayFiles.Text &= e.FullPath & _
                                    "- deleted" & vbCrLf
        End If


    End Sub

    Public Sub logrename(ByVal source As Object, ByVal e As _
                            System.IO.RenamedEventArgs)
        Me.txtDisplayFiles.Text &= "File" & e.OldName & _
                      " has been renamed to " & e.Name & vbCrLf
    End Sub

    Private Sub btnStopWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopWatch.Click

        ' Stop watching the folder
        watchfolder.EnableRaisingEvents = False
        btnStartWatch.Enabled = True
        btnStopWatch.Enabled = False
    End Sub
0
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
PockyMasterCommented:
If I look at your code I think you should OR your filters

WatchFolder.NotifyFilter = IO.NotifyFilters.DirectoryName
            WatchFolder.NotifyFilter = NotifyFilters.FileName
            WatchFolder.NotifyFilter = NotifyFilters.Attributes
becomes
WatchFolder.NotifyFilter = (IO.NotifyFilters.DirectoryName OR NotifyFilters.FileName OR  NotifyFilters.Attributes)

Try if you got all the filters you need

0
 
VBdotnet2005Author Commented:
That works. Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now