Link to home
Create AccountLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of VBdotnet2005

ASKER

That works. Thank you