os.listdir: which ones are directories?

Peter Hansen peter at engcorp.com
Tue Jan 15 00:39:24 EST 2002


Stephen Boulet wrote:
> 
> Does anyone know how to tell which of the strings from os.lisdir('somedir')
> are directories? Thanks.

>>> import os
>>> for i in os.listdir('.'):
...   if os.path.isdir(i): 
...     print 'Dir', i
Dir a
Dir RECYCLED
Dir TEMP
Dir dev
Dir bin
Dir backup
Dir WINDOWS
Dir Program Files
Dir My Documents
Dir cache

-Peter



More information about the Python-list mailing list