import os path = '' path_list=os.listdir(path) for filename in path_list: if os.path.splitext(filename)[1] == '.mhd': XXXXXX