{"id":1672,"date":"2011-04-06T11:21:46","date_gmt":"2011-04-06T11:21:46","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=1672"},"modified":"2011-04-06T11:22:42","modified_gmt":"2011-04-06T11:22:42","slug":"%e6%96%87%e4%bb%b6%e7%9b%91%e6%8e%a7%e7%b1%bbfilesystemwatch%e7%9b%91%e8%a7%86%e7%b3%bb%e7%bb%9f%e7%9b%ae%e5%bd%95%e3%80%81%e6%96%87%e4%bb%b6%e7%9a%84%e6%9b%b4%e6%96%b0%e3%80%81%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2011\/04\/06\/%e6%96%87%e4%bb%b6%e7%9b%91%e6%8e%a7%e7%b1%bbfilesystemwatch%e7%9b%91%e8%a7%86%e7%b3%bb%e7%bb%9f%e7%9b%ae%e5%bd%95%e3%80%81%e6%96%87%e4%bb%b6%e7%9a%84%e6%9b%b4%e6%96%b0%e3%80%81%e5%88%a0%e9%99%a4\/","title":{"rendered":"\u6587\u4ef6\u76d1\u63a7\u7c7bFileSystemWatch:\u76d1\u89c6\u7cfb\u7edf\u76ee\u5f55\u3001\u6587\u4ef6\u7684\u66f4\u65b0\u3001\u5220\u9664\u7b49"},"content":{"rendered":"<pre escaped=\"true\" lang=\"csharp\">\r\npublic class Watcher\r\n{\r\n\r\n    public static void Main()\r\n    {\r\n    Run();\r\n\r\n    }\r\n\r\n    [PermissionSet(SecurityAction.Demand, Name=\"FullTrust\")]\r\n    public static void Run()\r\n    {\r\n        string[] args = System.Environment.GetCommandLineArgs();\r\n\r\n        \/\/ If a directory is not specified, exit program.\r\n        if(args.Length != 2)\r\n        {\r\n            \/\/ Display the proper way to call the program.\r\n            Console.WriteLine(\"Usage: Watcher.exe (directory)\");\r\n            return;\r\n        }\r\n\r\n        \/\/ Create a new FileSystemWatcher and set its properties.\r\n        FileSystemWatcher watcher = new FileSystemWatcher();\r\n        watcher.Path = args[1];\r\n        \/* Watch for changes in LastAccess and LastWrite times, and\r\n           the renaming of files or directories. *\/\r\n        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite\r\n           | NotifyFilters.FileName | NotifyFilters.DirectoryName;\r\n        \/\/ Only watch text files.\r\n        watcher.Filter = \"*.txt\";\r\n\r\n        \/\/ Add event handlers.\r\n        watcher.Changed += new FileSystemEventHandler(OnChanged);\r\n        watcher.Created += new FileSystemEventHandler(OnChanged);\r\n        watcher.Deleted += new FileSystemEventHandler(OnChanged);\r\n        watcher.Renamed += new RenamedEventHandler(OnRenamed);\r\n\r\n        \/\/ Begin watching.\r\n        watcher.EnableRaisingEvents = true;\r\n\r\n        \/\/ Wait for the user to quit the program.\r\n        Console.WriteLine(\"Press \\'q\\' to quit the sample.\");\r\n        while(Console.Read()!='q');\r\n    }\r\n\r\n    \/\/ Define the event handlers.\r\n    private static void OnChanged(object source, FileSystemEventArgs e)\r\n    {\r\n        \/\/ Specify what is done when a file is changed, created, or deleted.\r\n       Console.WriteLine(\"File: \" +  e.FullPath + \" \" + e.ChangeType);\r\n    }\r\n\r\n    private static void OnRenamed(object source, RenamedEventArgs e)\r\n    {\r\n        \/\/ Specify what is done when a file is renamed.\r\n        Console.WriteLine(\"File: {0} renamed to {1}\", e.OldFullPath, e.FullPath);\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public class Watcher { public static void Main() { Run( [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-1672","post","type-post","status-publish","format-standard","hentry","category-14"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=1672"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1672\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=1672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=1672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=1672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}