>>> import os >>> path = '/usr/share/cups/charmaps' >>> text_files = [f for f in os.listdir(path) if f.endswith('.txt')] >>> text_files ['euc-cn.txt', 'euc-jp.txt', 'euc-kr.txt', 'euc-tw.txt', ... 'windows-950.txt']