Optimizing tips for os.listdir

Thomas 2002 at weholt.org
Mon Sep 27 06:44:24 EDT 2004


I'm doing this :

[os.path.join(path, p) for p in os.listdir(path) if \
os.path.isdir(os.path.join(path, p))]

to get a list of folders in a given directory, skipping all plain
files. When used on folders with lots of files,  it takes rather long
time to finish. Just doing  a listdir, filtering out all plain files
and a couple of joins, I didn't think this would take so long. 

Is there a faster way of doing stuff like this?

Best regards,
Thomas



More information about the Python-list mailing list