[Tutor] Listing files in directories recursively

VanL van@lindbergs.org
Mon, 16 Apr 2001 00:37:32 -0600


For what its worth, there is already a builtin that will do most of the work for
you:

>>> import os
>>>
>>> def walker(arg, dirname, names):
...     print arg, dirname, names
...
>>> os.path.walk('.', walker, 'Please show me:')
Please show: . ['Addons']
Please show: .\Addons ['avl-2.0.tar.gz', 'egenix-mx-base-2.0.0.win32-py2.0.exe',
 'egenix-mx-commercial-2.0.0.win32-py2.0.exe', 'eopl.tar.gz', 'HTMLgen', 'HTMLge
n.tar', 'NumPy', 'PyOpenGL-1.5.6.win32-py2.0.exe', 'win32all-138.exe', 'wxPython
-2.2.1-Py20b1.EXE']

hth,

VanL