How can I check if the listdir result a directory?

Paul Rubin http
Fri Mar 23 06:45:47 CET 2007


"Plissken.s at gmail.com" <Plissken.s at gmail.com> writes:
> for f in os.listdir("."):
>      // how can I check if 'f' a directory?

Your two approaches are 1) use os.stat (or stat.stat) and check the
mode bits; or 2) use os.listdir and catch the OSError exception you
get if you use it on a non-directory.



More information about the Python-list mailing list