1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | using System;
using System.IO;
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\filedumps";
/* Watch for changes in LastWrite times, and the renaming of files */
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
// watch text files
watcher.Filter = "*.txt";
// Add event handlers
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
// raise events
watcher.EnableRaisingEvents = true;
private static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
|