{"id":10599,"date":"2022-01-19T16:09:13","date_gmt":"2022-01-19T10:39:13","guid":{"rendered":"https:\/\/pynative.com\/?p=10599"},"modified":"2023-08-04T13:15:03","modified_gmt":"2023-08-04T07:45:03","slug":"python-list-files-in-directory-with-extension-txt","status":"publish","type":"post","link":"https:\/\/pynative.com\/python-list-files-in-directory-with-extension-txt\/","title":{"rendered":"Python list Files in Directory with Extension txt"},"content":{"rendered":"\n

In this Python tutorial, we will see how to list all files of a directory having a specific extension.<\/p>\n\n\n\n

Sometimes we need to list files having a specific extension before performing any operation on them. For example, if you wanted to copy<\/a> only text files from one location to another. In this case, we need to make sure we are only looking for files having a .txt<\/code> extension.<\/p>\n\n\n\n

We will use the following three methods<\/strong>.<\/p>\n\n\n\n

Table of contents<\/h2>