Search For A File Using Python

If you are a coder, then surely you must have came across a requirement wherein you need to search for a file in a given directory. Now, this directory could be any directory — it could be your immediate parent directory or it could be a grand grand parent.

In this article, I’ll explain you about how can you search for a file in a given directory using Python.

Required Package

To perform file search, we only need a package named os and this can be imported using below line of code:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store