Python Program to Find All File with .txt Extension Present Inside a Directory ( Using os)

bookmark

import os

for file in os.listdir("my_dir"):
    if file.endswith(".txt"):
        print(file)

 

Output

a.txt
b.txt
c.txt