Imports System.IO
Dim Checkdir As New FileSystemWatcher("d:\")
'مشخص کردن اینکه زیر شاخه ها را تحت نظر قرار دهد یا خیر
Checkdir.IncludeSubdirectories = True
'نوع تحت نظر قراردادن
Checkdir.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.LastWrite
AddHandler Checkdir.Created, AddressOf Checkdir_creat
'تابع مورد نظر که باید انجام شود
Private Sub Checkdir_creat(ByVal sender As Object, ByVal e As FileSystemEventArgs)
MsgBox("creat file")
End Sub
'مثال دیگری از تابع قابل اجرا
Private Sub Checkdir_Changed(ByVal sender As Object, ByVal e As FileSystemEventArgs)
' Write the path of a changed file to the console
MsgBox(e.ChangeType + ": " + e.FullPath)
End Sub