{"id":6846,"date":"2025-01-28T07:21:22","date_gmt":"2025-01-28T07:21:22","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6846"},"modified":"2026-01-27T08:34:20","modified_gmt":"2026-01-27T08:34:20","slug":"how-to-list-all-files-in-directory","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/","title":{"rendered":"How to List All Files in Directory"},"content":{"rendered":"\n<p>Sometimes Python developers need to get a list of all files in a directory. This is commonly required if your application or website needs to display a list of files from a folder. There are several simple ways to to do this using Python<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#The_Problem\" >The Problem<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#How_to_List_All_Files_in_Directory\" >How to List All Files in Directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#1_Using_listdir_function\" >1. Using listdir() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#2_Using_walk_function\" >2. Using walk() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#3_Using_globglob_function\" >3. Using glob.glob() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#4_List_Only_Files\" >4. List Only Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#5_List_Specific_File_Types\" >5. List Specific File Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#6_List_Subdirectories\" >6. List Subdirectories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#7_List_Parent_Folders\" >7. List Parent Folders<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Problem\"><\/span>The Problem<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes you may be building an application or a website, where you need to display a list of files in a directory, on a specific web page. For example, your app or website may need to feature an image gallery showing all uploaded images. Alternatively, you may need to iterate through all files in a folder and perform certain tasks on them. For example, you may need to go through all text files in a folder and process them. In all these cases, you will need to list all files in directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_List_All_Files_in_Directory\"><\/span>How to List All Files in Directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to list all files in directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_listdir_function\"><\/span>1. Using listdir() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python provides <em>os<\/em> module that provides many functions to work with operating systems and files. Among them listdir() is a popular function that returns a list of both files and sub directories in a directory. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.listdir(path)<\/pre>\n\n\n\n<p>In the above command, you need to provide the directory path for which you want to list files and subdirectories. It can be a relative or absolute path as per your requirement.<\/p>\n\n\n\n<p>Here is an example to get a list of files and subdirectories in directory &#8216;\/home\/ubuntu&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br>print(os.listdir('\/home\/ubuntu'))<\/pre>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['manuel.txt', '.qws', '.gnupg', ..., '.bashrc', '.wget-hsts', '.npm', '.viminfo', '.local']<\/pre>\n\n\n\n<p>Here is the command to view names of all files &amp; directories in current directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.listdir('.')<\/pre>\n\n\n\n<p>You can also use this command to list files &amp; directories in parent directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.listdir('..')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_walk_function\"><\/span>2. Using walk() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>OS module also provides a walk() function that takes path of the directory to be explored, and returns generator object containing 2 lists of files and directories. We need to loop through the generator to extract their names. Here is an example where we call os.walk() function on \/home\/ubuntu directory. We loop through the generator object to get the directory and file names and store them in another list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from os import walk<br><br>f = []<br>my_path = '\/home\/ubuntu'<br>for (dirpath, dirnames, filenames) in walk(my_path):<br>     f.extend(filenames)<br>     break<br><br>print(f)<\/pre>\n\n\n\n<p>Here is a sample output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['LICENSE.txt', 'MySQL-python-wininst.log', ... , 'README.txt', 'RemoveMySQL-python.exe', 'w9xpopen.exe']<\/pre>\n\n\n\n<p>Since os.walk() returns a generator object instead of final list, it is very memory efficient. So it is suitable if your directory contains large number of files and subdirectories. Also, since we loop through the iterator, we can selectively list files and sub directories instead of extracting all of them.<\/p>\n\n\n\n<p>Here is a shorter way to write the same code, if you only want to extract file names.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">filenames = next(walk(my_path), (None, None, []))[2]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_globglob_function\"><\/span>3. Using glob.glob() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python also provides glob module that allows you to effectively list files and directories. It provides glob() function that not only lists files and directories but allows you to do pattern matching. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">glob.glob(path_with_pattern)<\/pre>\n\n\n\n<p>In the above command, you need to provide path to the directory where you want glob() function to work, along with a pattern to match its files and sub directories.<\/p>\n\n\n\n<p>Please note, the above command will list all files and directories except ones that begin with dot(.) since they are hidden.<\/p>\n\n\n\n<p>Here is an example to list all files and directories in \/home\/ubuntu.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import glob<br>print(glob.glob('\/home\/ubuntu\/*'))<\/pre>\n\n\n\n<p>Here is a sample output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['\/home\/ubuntu\/remove-old-snaps', '\/home\/ubuntu\/gpush.sh', ..., '\/home\/ubuntu\/tweet.py', '\/home\/ubuntu\/t']<\/pre>\n\n\n\n<p>Please note, you need to provide wildcard character or other pattern to match the files and subdirectories in our target folder. Else it will only return the input directory. The following command will not give desired result.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(glob.glob('\/home\/ubuntu\/'))<\/pre>\n\n\n\n<p>If you want to only list .txt files in target directory, then mention it in your input directory pattern.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(glob.glob('\/home\/ubuntu\/*.txt'))<\/pre>\n\n\n\n<p>If you want to list all .txt files in current directory, you can simply mention the pattern matching for file extension.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(glob.glob('*.txt'))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_List_Only_Files\"><\/span>4. List Only Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We have seen that os.listdir(), os.walk() and glob.glob() are the most popular ways to list files and directories in Python. Now let us look at some common use cases. Often Python developers need to list only files. You can do this using listdir() and isfile() functions as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from os import listdir<br>from os.path import isfile, join<br>my_path = '\/home\/ubuntu'<br>files = [f for f in listdir(my_path) if isfile(join(my_path, f))]<\/pre>\n\n\n\n<p>In the above code, we first import listdir function from os module. We also import isfile and join functions from os.path. We use listdir() function to get a list of files and directories together. We use a list comprehension to loop through this list. In each iteration, we use join() function to obtain the full path to each file and directory. We also call isfile() function to check if the path is a file or directory. For all paths that return true for isfile() function, we store the path in files list. In the end, this list will contain all file paths only.<\/p>\n\n\n\n<p>If you are using os.walk() you can use the following short code for this purpose.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">filenames = next(walk(my_path), (None, None, []))[2]<\/pre>\n\n\n\n<p>os.walk() function returns a generator object to both files and directories. We loop through it to extract only file path.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_List_Specific_File_Types\"><\/span>5. List Specific File Types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to extract specific file types, then using glob.glob() function is your best bet. It allows you to easily specify a wide range of patterns to match file types. Here is an example to list all pdf files in \/home\/ubuntu directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">glob.glob('\/home\/ubuntu\/*.pdf')<\/pre>\n\n\n\n<p>In the above code, \/home\/ubuntu\/*.pdf stands for pattern to match all PDF files in \/home\/ubuntu. Here is a command to list all files starting with letter &#8216;a&#8217; in \/home\/ubuntu.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from glob import glob<br>from os.path import isfile, join<br>my_path = '\/home\/ubuntu\/a*'<br>files = [f for f in glob.glob(my_path) if isfile(join(my_path, f))]<\/pre>\n\n\n\n<p>In the above code, we import glob() function, along with isfile and join from os.path. Our pattern for path is &#8216;\/home\/ubuntu\/a*&#8217; meaning all files and directories starting with &#8216;a&#8217;. We use a list comprehension to loop through the list of paths in result of glob.glob() function. In each iteration, we use join() function to get full file path. We also call isfile() function to check if the path is file or not. Those paths that return true, are added list named files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_List_Subdirectories\"><\/span>6. List Subdirectories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to list only subdirectories, instead of files then you can slightly modify the above mentioned solution to get only directories. Here is an example using listdir() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from os import listdir<br>from os.path import isfile, join<br>my_path = '\/home\/ubuntu'<br>files = [f for f in listdir(my_path) if <strong>not<\/strong> isfile(join(my_path, f))]<\/pre>\n\n\n\n<p>In the above code, we import listdir function from os module. We also import isfile and join functions from os.path module. listdir function lists all files and folders in specific directory. We loop through this list and in each iteration call join function to get full path to file or directory. We also call isfile() function in each iteration. If this function returns false, we store the path in files list.<\/p>\n\n\n\n<p>You can similarly use glob.glob() function for this purpose. It provides greater flexibility with the ability to specify wildcard characters in folder path. Here is an example to list sub directories starting with letter &#8216;a&#8217; in \/home\/ubuntu\/<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from glob import glob<br>from os.path import isfile, join<br>my_path = '\/home\/ubuntu\/'<br>files = [f for f in glob(my_path) if <strong>not<\/strong> isfile(join(my_path, f))]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_List_Parent_Folders\"><\/span>7. List Parent Folders<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can use listdir() function to easily list files and directories in parent directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.listdir('..')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to list files and directories in Python. You can use any of these methods as per your requirement. If you have too many files and directories in your folder, use os.walk() since it returns a generator object to the list of files and folders. So it is fast and does not occupy much memory. If you are looking for certain amount of flexibility in specifying folder paths, extracting files of a specific file type, then use glob.glob() function.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-delete-file-or-folder-in-python\/\">How to Delete File or Folder in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/\">How to Copy Files in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/\">How to Iterate Ove Row in Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.<\/p>\n","protected":false},"author":1,"featured_media":6917,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[117],"class_list":["post-6846","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-list-files"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to List All Files in Directory - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to List All Files in Directory - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-28T07:21:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-27T08:34:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"260\" \/>\n\t<meta property=\"og:image:height\" content=\"173\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to List All Files in Directory\",\"datePublished\":\"2025-01-28T07:21:22+00:00\",\"dateModified\":\"2026-01-27T08:34:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\"},\"wordCount\":1260,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1\",\"keywords\":[\"list files\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\",\"name\":\"How to List All Files in Directory - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1\",\"datePublished\":\"2025-01-28T07:21:22+00:00\",\"dateModified\":\"2026-01-27T08:34:20+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1\",\"width\":260,\"height\":173,\"caption\":\"list files in directories\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to List All Files in Directory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to List All Files in Directory - Ubiq BI","description":"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.","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:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/","og_locale":"en_US","og_type":"article","og_title":"How to List All Files in Directory - Ubiq BI","og_description":"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-28T07:21:22+00:00","article_modified_time":"2026-01-27T08:34:20+00:00","og_image":[{"width":260,"height":173,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to List All Files in Directory","datePublished":"2025-01-28T07:21:22+00:00","dateModified":"2026-01-27T08:34:20+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/"},"wordCount":1260,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1","keywords":["list files"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/","name":"How to List All Files in Directory - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1","datePublished":"2025-01-28T07:21:22+00:00","dateModified":"2026-01-27T08:34:20+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to list files and directories on your disk. Here is how to list all files in directory.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1","width":260,"height":173,"caption":"list files in directories"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-files-in-directory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to List All Files in Directory"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/list-files-directories-python.jpg?fit=260%2C173&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Mq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=6846"}],"version-history":[{"count":42,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6846\/revisions"}],"predecessor-version":[{"id":10447,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6846\/revisions\/10447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6917"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}