{"id":4384,"date":"2023-11-24T11:54:44","date_gmt":"2023-11-24T11:54:44","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4384"},"modified":"2024-01-04T16:53:56","modified_gmt":"2024-01-04T16:53:56","slug":"working-with-directories","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/file-input-and-output\/working-with-directories","title":{"rendered":"Working With Directories"},"content":{"rendered":"\n<p><em>We use pathlib and forward slashes so that the Path() function can be used to automatically convert backslash to forward slash on Linux systems.<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Does directory exist?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>from pathlib import Path\n\nif not Path('C:\/MyDirectoryname').is_dir():\n   print(\"Does not exist\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create Directory<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>from pathlib import Path\nimport os\n\nif not Path('C:\/MyDirectoryname').is_dir():\n   os.makedirs('C:\/MyDirectoryname')<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We use pathlib and forward slashes so that the Path() function can be used to automatically convert backslash to forward slash on Linux systems. Does directory exist? Create Directory<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344],"tags":[],"class_list":["post-4384","post","type-post","status-publish","format-standard","hentry","category-file-input-and-output"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4384"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4384\/revisions"}],"predecessor-version":[{"id":4574,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4384\/revisions\/4574"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}