from os import walk f = [] for (dirpath, dirnames, filenames) in walk(mypath): f.extend(filenames) break