how to search directories under <PATH>

H

Haim Ashkenazi

Hi

I have to write a function that returns a list of all directories under
<PATH> (should work on linux and windows). it should be easy to write a
loop that goes through every directory... and so on, but I was wondering
if there's faster/more economic way, something like 'find <PATH> -type d'.
I couldn't find any 'find' module for python.

any ideas?

thanx
 
L

Larry Bates

os.path.exists() is what you want.

Secondly, If you want to traverse path
hierarchy use os.path.walk().

HTH,
Larry Bates
Syscon, Inc.
 
H

Haim Ashkenazi

os.path.exists() is what you want.

Secondly, If you want to traverse path
hierarchy use os.path.walk().
it shows I'm a newbie... :)

I already found out that os.walk do exactly what I want:

for root, dirs, files in walk(<PATH>):
for dir in dirs:
list.append(root + dir)

this will generate a list of directories under <PATH>

thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top