How to search a file directory in Python

Searching a file directory finds all files with a name matching a search query within a path. For example, a search for the file extension “.txt” would result in all text files contained within a directory.

Solution for How to search a file directory in Python : You can use pathlib.Path.glob() to search a directory Call pathlib.Path(directory).glob(query) where directory is the search directory and query is the search term. Use “*” to indicate any pattern can match with that part of the file name.


how-to-search-a-file-directory-in-python