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);
}




猜你喜欢

转载自www.cnblogs.com/yumiban/p/10271343.html
今日推荐