Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to search directories under <PATH>

Reply
Thread Tools

how to search directories under <PATH>

 
 
Haim Ashkenazi
Guest
Posts: n/a
 
      06-26-2004
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
--
Haim



 
Reply With Quote
 
 
 
 
Harald Massa
Guest
Posts: n/a
 
      06-26-2004
Haim,

google for python path module

cheers Harald
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      06-26-2004
os.path.exists() is what you want.

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

HTH,
Larry Bates
Syscon, Inc.

"Haim Ashkenazi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> --
> Haim
>
>
>



 
Reply With Quote
 
Haim Ashkenazi
Guest
Posts: n/a
 
      06-26-2004
On Sat, 26 Jun 2004 08:21:25 -0500, Larry Bates wrote:

> 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
--
Haim



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
virtual directories/physical directories in IIS Paul F ASP .Net 4 06-25-2008 04:04 PM
Multiple bin-directories with virtual directories? =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?= ASP .Net 0 11-09-2004 05:49 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments