Directory

brad byte8bits at gmail.com
Tue Jul 31 09:58:56 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.

How far down do you want to go?

All the way to the bottom:

for root, dirs, files in os.walk('.'):
     for d in dirs:
         print os.path.join(root, d)

####################################

Only your current directory:

x = os.listdir('.')
for item in x:
     if os.path.isdir(item):
         print item



More information about the Python-list mailing list