
The below example shows how to find files in the directory with a certain extension using the listdir() function and the endswith() function with the comprehension method. py are: var_1.py Example: Finding files with a certain extension using the comprehension py are: variables_2.pyįiles with extension. py are: Static_var.pyįiles with extension. py are: practice1.pyįiles with extension. py are: instance_var_examples.pyįiles with extension.

# Finding files with extension using for loopįiles with extension. The below example shows how to find files in the directory with certain extension using the listdir() function and the endswith() function. Write opeartion.png Example: Finding file using the endswith() Function Once we run the program we will get the following output. The below example shows how to find files in the directory using the listdir() function. Example: Finding files in a directory using the listdir() Function The glob.glob() function returns the file name with a specified pattern. The endswith() is an in-built function that returns True in this case, if the string ends with a particular specified suffix else it will return F alse.

py, we need to find that file.Īs we all know there are several methods to find the files, but in this tutorial, we will learn to find the files with certain extensions using the endswith() function, comprehension method, and the several methods present in the os module and glob module. But when we need to do certain operations on a file with a specific file extension like. We know how to find files and do operations on that file using the file handling methods.
