Imports System.IO Public Class Form1 Private Sub OnChanged(ByVal sender As Object, ByVal e As FileSystemEventArgs) ' Specify what is done when a file is changed, created, or deleted. ListBox1.Items.Add(e.FullPath & " " & e.ChangeType) Label6.Text = (e.FullPath & " " & e.ChangeType) Label1.Text += 1 End Sub Private Sub OnRenamed(ByVal sender As Object, ByVal e As RenamedEventArgs) ' Specify what is done when a file is renamed. ListBox1.Items.Add(e.FullPath & " " & e.ChangeType) Label6.Text = (e.FullPath & " " & e.ChangeType) Label1.Text += 1 End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load CheckForIllegalCrossThreadCalls = False FSW() End Sub Public Sub FSW() Dim drives As String() = Environment.GetLogicalDrives() For Each strDrive As String In drives 'Check if the drive is ready to be used Dim df As New DriveInfo(strDrive) If Not df.IsReady Then Continue For End If Dim _watcher As New FileSystemWatcher() _watcher.IncludeSubdirectories = True _watcher.Path = strDrive _watcher.NotifyFilter = NotifyFilters.Attributes Or NotifyFilters.CreationTime Or NotifyFilters.DirectoryName Or NotifyFilters.FileName _ Or NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.Security Or NotifyFilters.Size AddHandler _watcher.Changed, AddressOf OnChanged AddHandler _watcher.Created, AddressOf OnChanged AddHandler _watcher.Deleted, AddressOf OnChanged AddHandler _watcher.Renamed, AddressOf OnRenamed _watcher.EnableRaisingEvents = True Next End Sub End Class
FileSystemWatcher
AddHandler
RemoveHandler
allowHandling
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)