Directory

Larry Bates larry.bates at websafe.com
Thu Aug 2 10:05:35 EDT 2007


Rohan wrote:
> I would like to get a list of sub directories in a directory.
> If I use os.listdir i get a list of directories and files in that .
> i only want the list of directories in a directory and not the files
> in it.
> anyone has an idea regarding this.
> 

import os
listofdirs=[d for d in os.listdir(mydir) if os.pathisdir(d)]

-Larry



More information about the Python-list mailing list