我已经编写了这段代码来查看系统中的文件,但它不会提醒文件夹或文件中的任何修改。我怎样才能做到这一点?我不明白,因为它没有显示任何异常或错误。
static void Main(string[] args)
{
FileSystemWatcher();
}
public static void FileSystemWatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"D:\watcher";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
Console.Read();
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.Name + " has changed");
}