for filenames in os.walk(path):
    for file_list in filenames:
        for file_name in file_list:
            if file_name.endswith('.txt'):
                return_list.append(file_name)
return return_list
Browse files and subfolders in Python