Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Removing hidden directory in os.walk()

Reply
Thread Tools

Re: Removing hidden directory in os.walk()

 
 
Chris Rebert
Guest
Posts: n/a
 
      02-25-2011
On Fri, Feb 25, 2011 at 9:40 AM, Gaëtan Podevijn <(E-Mail Removed)> 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
 
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
Populate Hidden field on post back and retrieve value from Hidden Field Rick ASP .Net 3 04-13-2010 05:38 PM
Win 7 folders hidden despite 'show hidden' checked Boppy NZ Computing 10 01-23-2010 02:56 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
How would I discover the text in a block element hidden by overflow:hidden style being set? SolarCanine Javascript 2 09-20-2005 06:27 PM
Removing Hidden Folder Left by Mergring Parttions Zork Computer Support 0 08-02-2004 02:12 AM



Advertisments