{"id":92,"date":"2016-02-12T16:47:23","date_gmt":"2016-02-12T16:47:23","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=92"},"modified":"2022-02-17T06:24:15","modified_gmt":"2022-02-17T06:24:15","slug":"working-with-directories","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/file-input-and-output\/working-with-directories","title":{"rendered":"Working With Directories"},"content":{"rendered":"<pre>\r\n<code>\r\nusing System.IO;\r\n<\/code><\/pre>\n<h4>\n\tDoes directory exist?<br \/>\n<\/h4>\n<p>\n\t(Note paths can include a filename if you wish)\n<\/p>\n<pre>\r\n<code>\r\n\tif (!Directory.Exists(Path.GetDirectoryName(MyFileName)))\r\n\t\tDirectory.CreateDirectory(Path.GetDirectoryName(MyFileName));\r\n\t\/\/or\r\n\tString path;\r\n\tpath = &quot;C:\\\\Atest\\\\&quot;;\t\t\t\t\/\/\t\t&#39;\\\\&#39;=&#39;\\&#39;\r\n\tif (!Directory.Exists(path))\r\n\t\/\/or\r\n\tif (!Directory.Exists(&quot;C:\\\\Atest\\\\&quot;))\t\/\/\t\t&#39;\\\\&#39;=&#39;\\&#39;\r\n<\/code><\/pre>\n<h4>\n\tCreate Directory<br \/>\n<\/h4>\n<p>\n\t(Note paths can include a filename if you wish)\n<\/p>\n<pre>\r\n<code>\r\n\tDirectory.CreateDirectory(Path.GetDirectoryName(MyFileName));\r\n\t\/\/or\r\n\tString path;\r\n\tpath = &quot;C:\\\\Atest\\\\&quot;;\t\t\t\t\/\/\t\t&#39;\\\\&#39;=&#39;\\&#39;\r\n\tDirectory.CreateDirectory(path);\r\n\t\/\/or\r\n\tDirectory.CreateDirectory(&quot;C:\\\\Atest\\\\&quot;);\t\/\/\t\t&#39;\\\\&#39;=&#39;\\&#39;\r\n<\/code><\/pre>\n<h4>\n\tGet Directory From File Path<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tsTemp = Path.GetDirectoryName(MyFilename)\r\n<\/code><\/pre>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System.IO; Does directory exist? (Note paths can include a filename if you wish) if (!Directory.Exists(Path.GetDirectoryName(MyFileName))) Directory.CreateDirectory(Path.GetDirectoryName(MyFileName)); \/\/or String path; path = &quot;C:\\\\Atest\\\\&quot;; \/\/ &#39;\\\\&#39;=&#39;\\&#39; if (!Directory.Exists(path)) \/\/or if (!Directory.Exists(&quot;C:\\\\Atest\\\\&quot;)) \/\/ &#39;\\\\&#39;=&#39;\\&#39; Create Directory (Note paths can include a filename if you wish) Directory.CreateDirectory(Path.GetDirectoryName(MyFileName)); \/\/or String path; path = &quot;C:\\\\Atest\\\\&quot;; \/\/ &#39;\\\\&#39;=&#39;\\&#39; Directory.CreateDirectory(path); \/\/or Directory.CreateDirectory(&quot;C:\\\\Atest\\\\&quot;); [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-file-input-and-output"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/92\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}