C# 文件监视器简单例子源码
C# 文件监视器简单例子源码private void btn_FileWatcher_Click(object sender, EventArgs e)
{
FileSystemWatcher k8watcher = new FileSystemWatcher();
k8watcher.Path = "d:\\K8team";
k8watcher.IncludeSubdirectories = true;
k8watcher.EnableRaisingEvents = true;
k8watcher.SynchronizingObject = this;
k8watcher.Created += new FileSystemEventHandler(k8fileCreated);
k8watcher.Changed += new FileSystemEventHandler(k8fileChanged);
k8watcher.Renamed += new RenamedEventHandler(k8fileRenamed);
k8watcher.Deleted += new FileSystemEventHandler(k8fileDeleted);
}
public void k8fileCreated(object sender, FileSystemEventArgs e)
{
string log = string.Format(e.ChangeType + ":{0} --时间:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
txt_Relust.AppendText(log);
}
public void k8fileChanged(object sender, FileSystemEventArgs e)
{
string log = string.Format(e.ChangeType + ":{0} --时间:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
txt_Relust.AppendText(log);
}
public void k8fileDeleted(object sender, FileSystemEventArgs e)
{
string log = string.Format(e.ChangeType + ":{0} --时间:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
txt_Relust.AppendText(log);
}
public void k8fileRenamed(object sender,FileSystemEventArgs e)
{
string log = string.Format(e.ChangeType+":{0} --时间:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
txt_Relust.AppendText(log);
}
补充:软件开发 , C# ,