{"id":12932,"date":"2020-11-19T18:30:06","date_gmt":"2020-11-20T02:30:06","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12932"},"modified":"2023-12-01T04:04:14","modified_gmt":"2023-12-01T12:04:14","slug":"python-list-files-in-directory","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/","title":{"rendered":"Python List Files in a Directory: Step-By-Step Guide"},"content":{"rendered":"\n<p><em>The Python os library is used to list the files in a directory. The Python os.listdir() method returns a list of every file and folder in a directory. os.walk() function returns a list of every file in an entire file tree.  <\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Often, when you\u2019re working with files in Python, you\u2019ll encounter situations where you want to list the files in a directory. For instance, you may want to find all of the Python files in a folder.<\/p>\n\n\n\n<p>The Python os library offers a number of methods that can be used to list files in a directory. This tutorial will discuss how to use os.listdir() to get the files and folders in a director. We&#8217;ll also talk about using <em>os.walk()<\/em> to get the files and folders in a directory <em>and<\/em> in its subdirectories.\n\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python os Library<\/h2>\n\n\n\n<p>The Python os library provides a number of functions that you can use to work with operating systems. The functions included in the os module work on any modern operating system, whether it is Windows, Linux, or Mac.\n\n<\/p>\n\n\n\n<p>Since os is an external library, we need to import it into our code before we start using it. We can do so using a <a href=\"https:\/\/careerkarma.com\/blog\/python-import\/\">Python import statement<\/a>:\n\n<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os<\/pre><\/div>\n\n\n\n<p>Now that we\u2019ve imported the os library into our code, we can start using its functions to list items in a directory.\n\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python os.listdir()<\/h2>\n\n\n\n<p>In Python, the <em>os.listdir()<\/em> method lists files and folders in a given directory. The method does not return special entries such as \u2018.\u2019 and \u2018..\u2019, which the operating system uses to navigate through different directories.<\/p>\n\n\n\n<p>os.listdir() also does not return files and folders beyond the first level of folders. In other words, <em>os.listdir()<\/em> does not return anything within subfolders discovered by the method.<\/p>\n\n\n\n<p>The os.listdir() function accepts one parameter: the file path of the directory whose file and folder names you want to retrieve.&nbsp;\n\n<\/p>\n\n\n\n<p>Here\u2019s the syntax for the listdir method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>os.listdir(path)<\/pre><\/div>\n\n\n\n<p>Let\u2019s walk through an example to showcase how to use this method in a Python program.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">os.listdir() Python Example<\/h3>\n\n\n\n<p>Say that we are creating a program that analyzes the stock market performance of Netflix over the last decade. We have a folder (name: \/home\/data_analysis\/netflix) with all of our raw data, and before our program starts running, we want to check to make sure that the file <em>raw_data_2019.csv<\/em> exists within that folder. <\/p>\n\n\n\n<p>In order to function properly, our program needs that particular file to be stored in that particular folder.\n\n<\/p>\n\n\n\n<p>We could use the following code to retrieve a list of the files in the <em>\/home\/data_analysis\/netflix<\/em> work directory:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os\n\npath = '\/home\/data_analysis\/netflix'\n\nfiles = os.listdir(path)\n\nfor f in files:\n\tprint(f)\n<\/pre><\/div>\n\n\n\n<p>Our program retrieves a list of all files and folders in the specified directory and returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>README.md\napp.py\nraw_data_2016.csv\nraw_data_2017.csv\nraw_data_2018.csv\nraw_data_2019.csv\nprocessed_data\n<\/pre><\/div>\n\n\n\n<p>Now, we can check to see if the file <em>raw_data_2019.csv<\/em> is in the folder. As you can see, it is.\n\n<\/p>\n\n\n\n<p>Let\u2019s break down our code. On the first line, we import the os module, which we need to do in order to access the <em>os.listdir() <\/em>function. Then, we declare a <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">Python variable<\/a> called <em>path<\/em>, which stores the name of the path whose contents we want to retrieve.\n\n<\/p>\n\n\n\n<p>On the next line, we use the os.listdir() method to get a list of the files and folders in the <em>\/home\/data_analysis\/netflix<\/em> directory. Finally, we create a <a href=\"https:\/\/careerkarma.com\/blog\/python-for-loop\/\">Python for loop<\/a>. This loop iterates through every item in the list produced by <em>os.listdir()<\/em>. We print out the name of each file to the console using a <a href=\"https:\/\/careerkarma.com\/blog\/python-print-without-new-line\/\">Python print() statement<\/a>.\n\n<\/p>\n\n\n\n<p>The <em>\/home\/data_analysis\/netflix<\/em> directory contained six files and one directory. The directory is called<em> processed_data<\/em> and is distinguishable from the other files because it does not have an extension.\n\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python os.walk()<\/h2>\n\n\n\n<p>The <em>os.walk() <\/em>function retrieves a list of files contained within a tree. The method iterates over each directory in a tree. Then, os.walk() returns the name of every file and folder within a directory and any of its subdirectories.\n\n<\/p>\n\n\n\n<p>The syntax for the <em>os.walk()<\/em> method is as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>os.walk(top, topdown, onerror, followlinks)<\/pre><\/div>\n\n\n\n<p>The <em>os.walk()<\/em> method accepts four parameters:\n\n<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>top<\/strong> is the top directory whose component file and folder names you want to retrieve (required)<\/li><li><strong>topdown<\/strong>, when set to True, specifies that directories should be scanned from the top down. If this value is set to False, directories will be scanned from the bottom up (optional)<\/li><li><strong>onerror<\/strong> provides an error handler if an error is encountered (optional)<\/li><li><strong>followlinks<\/strong>, if set to True, visits folders referenced by system links (optional)<\/li><\/ul>\n\n\n\n<p>We are going to focus on the first two parameters since onerror and followlinks are more advanced and are not as commonly used.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">os.walk() Python Example<\/h3>\n\n\n\n<p>Let\u2019s say that we want to retrieve the names of all files in the <em>\/home\/data_analysis\/netflix<\/em> directory. We also want to find out what\u2019s enclosed within all subdirectories in that folder.\n\n<\/p>\n\n\n\n<p>As we discussed above, the <em>netflix<\/em> directory contains one folder: <em>processed_data<\/em>. We could use the following code to retrieve the names of all files in the <em>\/home\/data_analysis\/netflix<\/em> directory <em>and<\/em> its subdirectories:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os\n\npath = '\/home\/data_analysis\/netflix'\n\nfor root, directories, files in os.walk(path, topdown=False):\n\tfor name in files:\n\t\tprint(os.path.join(root, name))\n\tfor name in directories:\n\t\tprint(os.path.join(root, name))\n<\/pre><\/div>\n\n\n\n<p>Here\u2019s the output from our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/home\/data_analysis\/netflix\/README.md\n\/home\/data_analysis\/netflix\/app.py\n\/home\/data_analysis\/netflix\/raw_data_2016.csv\n\/home\/data_analysis\/netflix\/raw_data_2017.csv\n\/home\/data_analysis\/netflix\/raw_data_2018.csv\n\/home\/data_analysis\/netflix\/raw_data_2019.csv\n\/home\/data_analysis\/netflix\/processed_data\n\/home\/data_analysis\/netflix\/processed_data\/final.csv\n<\/pre><\/div>\n\n\n\n<p>We import the os module from which we reference the <em>os.walk() <\/em>and <em>os.path.join()<\/em> methods later in our code. Then, we declare a variable called<em> path<\/em>, which stores the path whose file names we want to discover.\n\n<\/p>\n\n\n\n<p>We then create a<em> for<\/em> loop that uses <em>os.walk()<\/em> to retrieve a list of all files and folders in the<em> path<\/em> directory. That loop iterates through the files and folders that os.walk() returns. It\u2019s worth noting that we specify the <em>topdown=False<\/em> parameter in the <em>os.walk()<\/em> method, which tells our code to conduct a top-down search.\n\n<\/p>\n\n\n\n<p>Our <em>for<\/em> loop iterates through each file and directory discovered by the os.walk() method using additional <em>for<\/em> loops. We print out the files in os.walk() to the console.\n\n<\/p>\n\n\n\n<p>In our code above, here are our <em>for<\/em> loops:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for root, directories, files in os.walk(path):\n\tfor name in files:\n\t\tprint(os.path.join(root, name))\n\tfor name in directories:\n\t\tprint(os.path.join(root, name))<\/pre><\/div>\n\n\n\n<p>Then, our program uses os.path.join() to join together the root folder of each file (<em>i.e. \/home\/data_analysis\/netflix<\/em>)and the name of the file (i.e. <em>raw_datra_2019.csv<\/em>). The root folder refers to the directory path in which a file exists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>You can use the Python <em>listdir()<\/em> method to do this. You can also use the <em>walk()<\/em> method, which lists everything in a directory, <em>including<\/em> anything within subdirectories.<\/p>\n\n\n\n<p>This guide explored, providing examples, how to use the <em>os.listdir() <\/em>and <em>os.walk()<\/em> methods to list files and folders in a directory in Python. Now you have the skills you need to list files in a directory in Python like an expert!<\/p>\n\n\n\n<p>To learn more about coding in Python, read our full <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-python\/\">How to Learn Python guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"The Python os library is used to list the files in a directory. The Python os.listdir() method returns a list of every file and folder in a directory. os.walk() function returns a list of every file in an entire file tree. Often, when you\u2019re working with files in Python, you\u2019ll encounter situations where you want&hellip;","protected":false},"author":240,"featured_media":12937,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12932","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python List Files in a Directory: Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python List Files in a Directory: Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-20T02:30:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:04:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"646\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python List Files in a Directory: Step-By-Step Guide\",\"datePublished\":\"2020-11-20T02:30:06+00:00\",\"dateModified\":\"2023-12-01T12:04:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/\"},\"wordCount\":1143,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/nescafe-cup-near-imac-225502.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/\",\"name\":\"Python List Files in a Directory: Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/nescafe-cup-near-imac-225502.jpg\",\"datePublished\":\"2020-11-20T02:30:06+00:00\",\"dateModified\":\"2023-12-01T12:04:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/nescafe-cup-near-imac-225502.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/nescafe-cup-near-imac-225502.jpg\",\"width\":1000,\"height\":646},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-list-files-in-directory\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python List Files in a Directory: Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python List Files in a Directory: Step-By-Step Guide | Career Karma","description":"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/","og_locale":"en_US","og_type":"article","og_title":"Python List Files in a Directory: Step-By-Step Guide","og_description":"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.","og_url":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-11-20T02:30:06+00:00","article_modified_time":"2023-12-01T12:04:14+00:00","og_image":[{"width":1000,"height":646,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python List Files in a Directory: Step-By-Step Guide","datePublished":"2020-11-20T02:30:06+00:00","dateModified":"2023-12-01T12:04:14+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/"},"wordCount":1143,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/","url":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/","name":"Python List Files in a Directory: Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg","datePublished":"2020-11-20T02:30:06+00:00","dateModified":"2023-12-01T12:04:14+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Listing files is a common operation in Python. On Career Karma, learn how to list files in a directory using os.listdir and os.walk.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/nescafe-cup-near-imac-225502.jpg","width":1000,"height":646},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-list-files-in-directory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python List Files in a Directory: Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12932"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12932\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12937"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}