import os faililoetelu=os.listdir(".") for fail in faililoetelu: if fail.endswith(".txt"): print fail