{"id":229,"date":"2010-09-30T11:53:41","date_gmt":"2010-09-30T11:53:41","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=229"},"modified":"2010-09-30T11:55:18","modified_gmt":"2010-09-30T11:55:18","slug":"%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/09\/30\/%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c\/","title":{"rendered":"\u6587\u4ef6\u64cd\u4f5c"},"content":{"rendered":"<p> 1\uff0c\u904d\u5386<br \/>\nC#\u904d\u5386\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6<br \/>\nDirectoryInfo TheFolder=new DirectoryInfo(folderFullName);<br \/>\n\/\/\u904d\u5386\u6587\u4ef6\u5939<br \/>\nforeach(DirectoryInfo NextFolder in TheFolder.GetDirectories())<br \/>\n   this.listBox1.Items.Add(NextFolder.Name);<br \/>\n\/\/\u904d\u5386\u6587\u4ef6<br \/>\nforeach(FileInfo NextFile in TheFolder.GetFiles())   \/\/foreach(FileInfo NextFile in TheFolder.GetFiles(&#8220;*.cs&#8221;)) \u627e\u7c7b\u6587\u4ef6<br \/>\n   this.listBox2.Items.Add(NextFile.Name); <\/p>\n<p>    FileInfo.Exists\uff1a\u83b7\u53d6\u6307\u5b9a\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff1b<br \/>\n    FileInfo.Name\uff0cFileInfo.Extensioin\uff1a\u83b7\u53d6\u6587\u4ef6\u7684\u540d\u79f0\u548c\u6269\u5c55\u540d\uff1b<br \/>\n    FileInfo.FullName\uff1a\u83b7\u53d6\u6587\u4ef6\u7684\u5168\u9650\u5b9a\u540d\u79f0\uff08\u5b8c\u6574\u8def\u5f84\uff09\uff1b<br \/>\n    FileInfo.Directory\uff1a\u83b7\u53d6\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff0c\u8fd4\u56de\u7c7b\u578b\u4e3aDirectoryInfo\uff1b<br \/>\n    FileInfo.DirectoryName\uff1a\u83b7\u53d6\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u7684\u8def\u5f84\uff08\u5b8c\u6574\u8def\u5f84\uff09\uff1b<br \/>\n    FileInfo.Length\uff1a\u83b7\u53d6\u6587\u4ef6\u7684\u5927\u5c0f\uff08\u5b57\u8282\u6570\uff09\uff1b<br \/>\n    FileInfo.IsReadOnly\uff1a\u83b7\u53d6\u6587\u4ef6\u662f\u5426\u53ea\u8bfb\uff1b<br \/>\n    FileInfo.Attributes\uff1a\u83b7\u53d6\u6216\u8bbe\u7f6e\u6307\u5b9a\u6587\u4ef6\u7684\u5c5e\u6027\uff0c\u8fd4\u56de\u7c7b\u578b\u4e3aFileAttributes\u679a\u4e3e\uff0c\u53ef\u4ee5\u662f\u591a\u4e2a\u503c\u7684\u7ec4\u5408<br \/>\n    FileInfo.CreationTime\u3001FileInfo.LastAccessTime\u3001FileInfo.LastWriteTime\uff1a\u5206\u522b\u7528\u4e8e\u83b7\u53d6\u6587\u4ef6\u7684\u521b\u5efa\u65f6\u95f4\u3001\u8bbf\u95ee\u65f6\u95f4\u3001\u4fee\u6539\u65f6\u95f4\uff1b<\/p>\n<p>2\uff0c\u8bfb\u5199<\/p>\n<pre lang=\"csharp\">\r\n\r\n \/\/\u521b\u5efa\u5e76\u5199\u5165(\u5c06\u8986\u76d6\u5df2\u6709\u6587\u4ef6)\r\n      if (!File.Exists(path))\r\n      {          \r\n         using (StreamWriter sw = File.CreateText(path))\r\n         {\r\n            sw.WriteLine(\"Hello\");\r\n         } \r\n      }\r\n      \/\/\u8bfb\u53d6\u6587\u4ef6\r\n      using (StreamReader sr = File.OpenText(path)) \r\n      {\r\n        string s = \"\";\r\n        while ((s = sr.ReadLine()) != null) \r\n        {\r\n           Console.WriteLine(s);\r\n             if (s.IndexOf(\"aaa\") != -1)\r\n                {\r\n                   \/\/.... \u641c\u7d22\u6587\u4ef6\u662f\u5426\u5305\u542b\u67d0\u5173\u952e\u5b57\r\n                }\r\n        }\r\n     }\r\n     \/\/\u5220\u9664\/\u62f7\u8d1d\r\n     try \r\n     {\r\n        File.Delete(path);\r\n        File.Copy(path, @\"f:\\tt.txt\");\r\n     } \r\n     catch (Exception e) \r\n     {\r\n        Console.WriteLine(\"The process failed: {0}\", e.ToString());\r\n     }\r\n   }\r\n\r\n\r\n\/\/\u67e5\u627e\u5173\u952e\u5b57\u662f\u5426\u5b58\u5728\u4e8e\u6307\u5b9a\u76ee\u6807\u6240\u6709\u6587\u4ef6\u4e2d\u7684\u4efb\u4e00\r\n    private void SearchKeyWordListInDirectroyFiles(string DirectoryPath, IList KeyWordsList,string filePattern ) {\r\n        \/\/KeyWordsList,\u5173\u952e\u5b57\u96c6\u5408\uff0cfilePattern\u6307\u5b9a\u641c\u7d22\u54ea\u4e9b\u6587\u4ef6\uff0cnotFile\u6307\u5b9a\u4e0d\u641c\u7d22\u54ea\u4e2a\u6587\u4ef6\r\n        try\r\n        {\r\n            DirectoryInfo di = new DirectoryInfo(DirectoryPath);\r\n            foreach (FileInfo NextFile in di.GetFiles(filePattern))\r\n            {\r\n                using (StreamReader sr = NextFile.OpenText())\r\n                    {\r\n                        string s = \"\";\r\n                        while ((s = sr.ReadLine()) != null)\r\n                        {\r\n                            for (int i = 0; i < KeyWordsList.Count; i++)\r\n                            {\r\n                                if (s.IndexOf(KeyWordsList[i].ToString()) != -1)\r\n                                {\r\n                                    KeyWordsList.RemoveAt(i);\r\n                                }\r\n                            }\r\n                        }\r\n                    }\r\n                \r\n            }\r\n\r\n            foreach (DirectoryInfo NextFolder in di.GetDirectories())\r\n            {\r\n                SearchKeyWordListInDirectroyFiles(NextFolder.FullName, KeyWordsList, filePattern);\r\n            }\r\n\r\n        }\r\n        catch (Exception e) { \r\n            \r\n        }\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u904d\u5386 C#\u904d\u5386\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6 DirectoryInfo TheFolder=new Direct [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-csharp"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/229","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=229"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}