import os, sys, glob
def getFilelist(root):
def listIter(subroot):
'''Local recursive function.'''
for name in glob.glob(os.path.join(subroot, '*')):
print name
listIter(name)
listIter(root) # Call recursion.
if __name__ == '__main__':
sys.exit(getFilelist(r'd:\example'))
In case of searching the group of certain files or folders among the huge amount of files - this search has better performance.