Given a suffix and a directory path, I need to extract the full path of the files in the directory that ends with a given suffix.
Currently, I'm doing it as such:
import os
dir_path = '/path/to/dir'
suffix = '.xyz'
filenames = filter(lambda x: x.endswith(suffix), os.listdir(dir_path))
filenames = map(lambda x: os.path.join(dir_path, x), filenames)
I could also do it with glob:
import glob
dir_path = '/path/to/dir'
suffix = '.xyz'
glob.glob(dir_path+'*.'+suffix)
I understand that there's also pathlib that can check for suffixes using PurePath but I'm not sure what is the syntax for that.
Are there other ways of achieving the same filtered list of full paths to the files?