how to search directories under <PATH>

Discussion in 'Python' started by Haim Ashkenazi, Jun 26, 2004.

  1. 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
     
    Haim Ashkenazi, Jun 26, 2004
    #1
    1. Advertising

  2. Haim Ashkenazi

    Harald Massa Guest

    Haim,

    google for python path module

    cheers Harald
     
    Harald Massa, Jun 26, 2004
    #2
    1. Advertising

  3. Haim Ashkenazi

    Larry Bates Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
     
    Larry Bates, Jun 26, 2004
    #3
  4. 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
     
    Haim Ashkenazi, Jun 26, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Finkel
    Replies:
    0
    Views:
    493
    Joel Finkel
    Sep 12, 2003
  2. Jeffry van de Vuurst
    Replies:
    2
    Views:
    531
    Jeffry van de Vuurst
    Jul 30, 2003
  3. =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=

    Multiple bin-directories with virtual directories?

    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    830
    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=
    Nov 9, 2004
  4. Paul F
    Replies:
    4
    Views:
    636
    Mark Fitzpatrick
    Jun 25, 2008
  5. Adam Petrie
    Replies:
    8
    Views:
    307
    Adam Petrie
    Oct 11, 2004
Loading...

Share This Page