Re: Removing hidden directory in os.walk()

Discussion in 'Python' started by Chris Rebert, Feb 25, 2011.

  1. Chris Rebert

    Chris Rebert Guest

    On Fri, Feb 25, 2011 at 9:40 AM, Gaëtan Podevijn <> wrote:
    > Hello,
    > I would like that os.walk() does not walk through hidden directories. I know
    > that with topdow = true, I can modify the subdirectory list in place, but
    > how should I remove every hidden directory from this place in list ?


    Assuming you're on *nix:

    for dirpath, dirnames, filenames in os.walk(top):
    dirnames[:] = [d for d in dirnames if not d.startswith('.')]
    do_whatever()

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Feb 25, 2011
    #1
    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. SD
    Replies:
    1
    Views:
    448
  2. SB
    Replies:
    3
    Views:
    310
    Tim Roberts
    Jan 15, 2006
  3. Replies:
    11
    Views:
    426
    Peter Otten
    Mar 2, 2007
  4. Marcus Alves Grando
    Replies:
    7
    Views:
    470
    Marcus Alves Grando
    Nov 14, 2007
  5. Steve Holden
    Replies:
    0
    Views:
    489
    Steve Holden
    Feb 26, 2009
Loading...

Share This Page