⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample9.cs

📁 C#函数手册
💻 CS
字号:
namespace apiBook
{
	using System;
	using System.IO;	
	public class TestFileSystemWatcherClass
	{
		public static void Main()
		{
			string path="C:\\language";
			FileSystemWatcher testFSW= new FileSystemWatcher();
			testFSW.Path = path;
			testFSW.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
				| NotifyFilters.FileName | NotifyFilters.DirectoryName;
			testFSW.Filter = "*.txt";
			testFSW.Changed += new FileSystemEventHandler(OnChanged);
			testFSW.Created += new FileSystemEventHandler(OnCreated);
			testFSW.Deleted += new FileSystemEventHandler(OnDeleted);
			testFSW.Renamed += new RenamedEventHandler(OnRenamed);
			testFSW.EnableRaisingEvents = true;
			Console.WriteLine("请按\'q\'退出监视。");
			while(Console.Read()!='q');
		}
		public static void OnChanged(object obj, FileSystemEventArgs e)
		{
			Console.WriteLine("文件: " +  e.FullPath + "被修改过" + e.ChangeType);
		}
		//重写OnChanged方法
		public static void OnDeleted(object obj, FileSystemEventArgs e)
		{
			Console.WriteLine("文件: " +  e.FullPath + "被删除" + e.ChangeType);
		}
		//重写OnDeleted方法
		public static void OnCreated(object obj, FileSystemEventArgs e)
		{
			Console.WriteLine("文件: " +  e.FullPath + "被创建");
		}
		//重写OnCreated方法
		public static void OnRenamed(object obj, RenamedEventArgs e)
		{
			Console.WriteLine("文件"+e.OldFullPath+"改名为"+ e.FullPath);
		}
		//重写OnRenamed方法
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -