The FileSystemWatcher class is used to create a function that watches activities being performed on files sitting in a folder. When running it will throw an event whenever a file is added, changed, deleted, or renamed.
Actually I found several suprisingly good websites.
Note: I created a form, and placed the code within the form. I did this because If I created a main() routine, it would execute, and then terminate and the FileSystemWatcher would not be running. By creating the form I know that the FileSystemWatcher is functioning because the window is open.
On the form I added a textbox control:
A directory to watch named ‘txtDir’. it is populated with the folder being watched
Here is a stripped down version of the code behind the form
Imports System Imports System.IO Imports System.Diagnostics Imports System.Windows.Forms
PublicClass theMain Public watchfolder As FileSystemWatcher
PrivateSub theMain_Load(sender AsObject, e As EventArgs) HandlesMyBase.Load Dim cmdline AsString _ = Command() Dim cmd() AsString _ = cmdline.Split(" ")
Console.WriteLine("Directory Watch Utility") Console.WriteLine("Creates a log of files added, modified, created, " _ & "deleted, or renamed for a specific directory") Console.WriteLine("") Console.WriteLine("Usage") Console.WriteLine(" DirWatch DirectoryToWatch ") Console.WriteLine("") If cmd.Length < 2Then End EndIf txtDir.Text = cmd(0)