import os
dir="/path/to/dir"
[x[0]+"/"+f for x in os.walk(dir) for f in x[2] if f.endswith(".jpg")]
This will give you a list of jpg files with their full path. You can replace x[0]+"/"+f
with f
for just filenames. You can also replace f.endswith(".jpg")
with whatever string condition you wish.