Created
January 29, 2010 21:49
-
-
Save robertgreiner/290178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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