import os fn=[filename for filename in os.listdir('D:\Programs\Python\Python37') if filename.endswith(('.exe','.py'))] print(fn)