import os fn = [filename for filename in os.listdir('F:\PYTHONwork\SpyderPython') if filename.endswith((',exe', '.py'))] print(fn)