Get all subdirs

xtian wilberforce at
Sun Aug 29 09:22:41 EDT 2004

Florian Lindner wrote:
> Hello,
> how can I get all subdirectories of a given directory.
> doesn't differentiate between directories and files, os.walk seems to
me a
> bit overkill since it also descends in the subdirs.
> Thx,
> Florian

Use os.path.isdir():

>>> from os.path import isdir, join
>>> d = "c:/downloads/python"
>>> subdirs = [sub for sub in os.listdir(d) if isdir(join(d, sub))]
>>> print subdirs
['adodbapi-2.0.1', 'pyblosxom', 'pygame', 'quasi_08']


More information about the Python-list mailing list