当前位置:编程学习 > C#/ASP.NET >>

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# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,