Hi , In this article we're going to learn how to watch the folder activity using VB.Net
Private Sub FileSystemWatcher1_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
ListBox1.Items.Add("Modified: " & e.FullPath)
End Sub
Private Sub btnsetpath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsetpath.Click
Try
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
'select folder
folder_txt.Text = FolderBrowserDialog1.SelectedPath
FileSystemWatcher1.Path = folder_txt.Text
End If
Catch ex As Exception
MsgBox(ex.Message, vbCritical, "File System Watcher")
End Try
End Sub
Private Sub FileSystemWatcher1_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
'if any file created add fullpath to the listbox
ListBox1.Items.Add("Created: " & e.FullPath)
End Sub
Private Sub FileSystemWatcher1_Deleted(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Deleted
'if any file deleted add fullpath to the listbox
ListBox1.Items.Add("Deleted: " & e.FullPath)
End Sub
Private Sub FileSystemWatcher1_Renamed(ByVal sender As System.Object, ByVal e As System.IO.RenamedEventArgs) Handles FileSystemWatcher1.Renamed
'if any file renamed add path to the listbox
ListBox1.Items.Add("Renamed: " & e.FullPath)
End Sub
