Skip to content

Instantly share code, notes, and snippets.

@robertgreiner
Created January 29, 2010 21:49
Show Gist options
  • Save robertgreiner/290178 to your computer and use it in GitHub Desktop.
Save robertgreiner/290178 to your computer and use it in GitHub Desktop.
/**
* This is a proof of concept to show that it is possible to monitor a directory for changes.
*/
using System;
using System.Text;
using System.IO;
namespace FolderWatcher {
class Watcher {
static void Main(string[] args) {
FileSystemWatcher watcher = new FileSystemWatcher(@"D:\test");
watcher.IncludeSubdirectories = true;
watcher.Filter = "";
watcher.Renamed += new RenamedEventHandler(renamed);
watcher.Deleted += new FileSystemEventHandler(changed);
watcher.Changed += new FileSystemEventHandler(changed);
watcher.Created += new FileSystemEventHandler(changed);
watcher.EnableRaisingEvents = true;
Console.ReadKey();
}
private static void renamed(object sender, RenamedEventArgs e) {
Console.WriteLine(e.ChangeType + " " + e.FullPath + " " + e.Name);
}
private static void changed(object sender, FileSystemEventArgs e) {
Console.WriteLine(DateTime.Now + ": " + e.ChangeType + " " + e.FullPath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment