Listing only directories?
Richard
richardd at hmgcc.gov.uk
Mon Jun 2 06:01:55 EDT 2003
Hi,
I am using os.listdir(root) to get a file and directory listing of the
'root' directory. However I am trying to filter out only the directories in
this listing.
I have tried the following (after reading up in the manual):
def listDirectories(root):
[f for f in os.listdir(root) if os.path.isdir(f)]
return f
but this doesn't seem to do what I want it to, only seeming to return the
name of one of the directories it finds.
Can anyone tell me what I am doing wrong, and if I'm barking up completely
the wrong tree?
Cheers
Richard D
More information about the Python-list
mailing list