1import os
2directory = 'the/directory/you/want/to/use'
3
4for filename in os.listdir(directory):
5 if filename.endswith(".txt"):
6 #do smth
7 continue
8 else:
9 continue
1import os
2
3directory = r'C:\Users\admin'
4for filename in os.listdir(directory):
5 if filename.endswith(".jpg") or filename.endswith(".png"):
6 print(os.path.join(directory, filename))
7 else:
8 continue