{"id":2156,"date":"2019-06-16T11:59:53","date_gmt":"2019-06-16T09:59:53","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=2156"},"modified":"2019-06-16T11:59:53","modified_gmt":"2019-06-16T09:59:53","slug":"search-files-with-python","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/search-files-with-python\/","title":{"rendered":"Search files with Python"},"content":{"rendered":"<p>With Python you can go look for files in such a fast way and you can also do things like memorize the path&#8230; etc.<\/p>\n<p>Let&#8217;s go take a look at the code and follow my explanation in the video below.<\/p>\n<pre class=\"lang:default decode:true \">import os\r\n\r\ndef searchfiles(word_in_title='example', folder='H:\\\\'):\r\n    \"\"\"Create a txt file with all the file of a type\"\"\"\r\n    with open(word_in_title + \"_files.txt\", \"w\", encoding=\"utf-8\") as filewrite:\r\n        for r, d, f in os.walk(\"H:\\\\\"):\r\n            for filetitle in f:\r\n                if word_in_title in filetitle:\r\n                    filewrite.write(f\"{r + filetitle}\\n\")\r\n\r\n# looking for png file (fonts) in the hard disk H:\\\r\nsearchfiles('.png', 'H:\\\\')<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"Search files with Python\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/3ZwPg6tHYc0?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":"With Python you can go look for files in such a fast way and you can also do things like memorize the path&#8230; \n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/search-files-with-python\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":2157,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-2156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples"],"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\/2156","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=2156"}],"version-history":[{"count":1,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2156\/revisions"}],"predecessor-version":[{"id":2158,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2156\/revisions\/2158"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/2157"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=2156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=2156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=2156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}