C#监控指定目录的文件变化的代码

如下的资料是关于C#监控指定目录的文件变化的代码。
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:mydir";

watcher.Created += new FileSystemEventHandler(watcher_Changed);
watcher.Deleted += new FileSystemEventHandler(watcher_Changed);

watcher.EnableRaisingEvents = true;

static void watcher_Changed(object sender,FileSystemEventArgs e)
{
Console.WriteLine("Directory changed({0}): {1}",
e.ChangeType,
e.FullPath);
}




 

posted @ 2019-01-15 13:23  玉米帮  阅读(452)  评论(0编辑  收藏  举报