{"id":2030,"date":"2019-05-19T06:07:14","date_gmt":"2019-05-19T04:07:14","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=2030"},"modified":"2019-05-19T06:55:56","modified_gmt":"2019-05-19T04:55:56","slug":"check-if-a-dir-exists","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/check-if-a-dir-exists\/","title":{"rendered":"Check if a dir exists"},"content":{"rendered":"<p>We will create a directory and the we will check if it exists, avoiding receiving an error message. We checked two ways to do it. The first uses os.path.isdir to check the presence of the directory, while the second uses the try except method to intercept the error.<\/p>\n<p><iframe loading=\"lazy\" title=\"Python basic stuffs - Create a dir and check if it exists\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/aXxoxW25tHo?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"Create a directory and check if it exists or avoid the error message.\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/check-if-a-dir-exists\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":1512,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[210,1],"tags":[391,389,228,390,388],"class_list":["post-2030","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basics","category-examples","tag-create-directory","tag-except","tag-os-module","tag-os-mkdir","tag-try"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=2030"}],"version-history":[{"count":3,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2030\/revisions"}],"predecessor-version":[{"id":2033,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2030\/revisions\/2033"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/1512"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=2030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=2030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=2030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}