using os

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Juliano Freitas

    #1

    using os

    how can i get just the directories in other directorie without a files
    using the os module in Python??


    Juliano



  • Jeffrey Froman

    #2
    Re: using os

    Juliano Freitas wrote:
    [color=blue]
    > how can i get just the directories in other directorie without a files
    > using the os module in Python??[/color]

    You can test using os.path.isdir, for example:
    [color=blue][color=green][color=darkred]
    >>> import os
    >>> [x for x in os.listdir('.') if os.path.isdir(x )][/color][/color][/color]


    Jeffrey

    Comment

    • Jean Brouwers

      #3
      Re: using os


      Check the os.walk() and os.path.walk() functions. More details and
      some examples are at

      <http://docs.python.org/lib/os-file-dir.html>

      resp.

      <http://docs.python.org/lib/module-os.path.html>


      /Jean Brouwers



      In article <mailman.6890.1 101764022.5135. python-list@python.org >,
      Juliano Freitas <jubafre@atlas. ucpel.tche.br> wrote:
      [color=blue]
      > how can i get just the directories in other directorie without a files
      > using the os module in Python??
      >
      >
      > Juliano
      >
      >
      >[/color]

      Comment

      • Jerry Sievers

        #4
        Re: using os

        Juliano Freitas <jubafre@atlas. ucpel.tche.br> writes:
        [color=blue]
        > how can i get just the directories in other directorie without a
        > files using the os module in Python??[/color]

        If there's a command for listing only dirs, I've not stumbled on it.

        Here's a one-liner using filter and lambda;

        from os import listdir
        from os.path import isdir

        dir = '/tmp/'

        onlyDirs = filter(lambda entry: isdir(dir + entry), listdir(dir))

        HTH


        --
        -------------------------------------------------------------------------------
        Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
        305 321-1144 (mobile http://www.JerrySievers.com/

        Comment

        Working...