Get all subdirs

Stephen Boulet stephen at SPAM.theboulets.IS.BAD.net
Sun Aug 29 10:45:02 EDT 2004


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

I'm a fan of the path module:

from path import path

p = path("my_directory")
l = [i.name for i in p.dirs()]

Stephen



More information about the Python-list mailing list