VB 2010 – Üerwachungsprogramm

Video <- hier klicken

Imports System.IO

Public Class Form1

    Private watchPath As String = "c:/"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim watcher As New FileSystemWatcher(watchPath)

        watcher.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.FileName
        watcher.Filter = "*.*"

        AddHandler watcher.Changed, AddressOf OnChanged
        AddHandler watcher.Created, AddressOf OnChanged
        AddHandler watcher.Deleted, AddressOf OnChanged
        AddHandler watcher.Renamed, AddressOf Onrenamed

        watcher.SynchronizingObject = Me

        watcher.EnableRaisingEvents = True

    End Sub

    Private Sub OnChanged(ByVal Source As Object, ByVal e As FileSystemEventArgs)

        ListBox1.Items.Add("Datei: " & e.FullPath() & "  " & e.ChangeType.ToString())

    End Sub

    Private Sub Onrenamed(ByVal Source As Object, ByVal e As RenamedEventArgs)

        ListBox1.Items.Add("Datei: " & e.OldFullPath() & "  umbenannt in " & e.FullPath)

    End Sub
End Class
Über

Francesco -- Windows & Linux -User, Blogger und Informatiker.

Veröffentlicht in Allgemein